本文整理汇总了Java中java.awt.Robot.keyRelease方法的典型用法代码示例。如果您正苦于以下问题:Java Robot.keyRelease方法的具体用法?Java Robot.keyRelease怎么用?Java Robot.keyRelease使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Robot
的用法示例。
在下文中一共展示了Robot.keyRelease方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.awt.Robot; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
final boolean dump = Boolean.parseBoolean(args[0]);
final Window w = new Frame() {
@Override
public void list(final PrintStream out, final int indent) {
super.list(out, indent);
dumped = true;
}
};
w.setSize(200, 200);
w.setLocationRelativeTo(null);
w.setVisible(true);
final Robot robot = new Robot();
robot.setAutoDelay(50);
robot.setAutoWaitForIdle(true);
robot.mouseMove(w.getX() + w.getWidth() / 2,
w.getY() + w.getHeight() / 2);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_F1);
robot.keyRelease(KeyEvent.VK_F1);
robot.keyRelease(KeyEvent.VK_SHIFT);
robot.keyRelease(KeyEvent.VK_CONTROL);
w.dispose();
if (dumped != dump) {
throw new RuntimeException("Exp:" + dump + ", actual:" + dumped);
}
}
示例2: checkFileChooser
import java.awt.Robot; //导入方法依赖的package包/类
private static void checkFileChooser() throws Exception {
if (System.getSecurityManager() == null) {
throw new RuntimeException("Security manager is not set!");
}
Robot robot = new Robot();
robot.setAutoDelay(50);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
fileChooser = new JFileChooser();
fileChooser.showOpenDialog(null);
fileChooserIsShown = true;
System.out.println("Start file chooser: " + fileChooserIsShown);
}
});
long time = System.currentTimeMillis();
while (fileChooser == null) {
if (System.currentTimeMillis() - time >= 10000) {
throw new RuntimeException("FileChoser is not shown!");
}
Thread.sleep(500);
}
Thread.sleep(500);
robot.keyPress(KeyEvent.VK_ESCAPE);
robot.keyRelease(KeyEvent.VK_ESCAPE);
System.exit(0);
}
示例3: execute
import java.awt.Robot; //导入方法依赖的package包/类
@Override
public void execute(@NotNull String pattern) {
try {
Robot r = new Robot();
r.keyPress(157);
r.keyPress(90);
r.keyRelease(90);
r.keyRelease(157);
} catch (AWTException e) {
e.printStackTrace();
}
SelectionUtil.selectNode(_context.getEditorContext(), _context.getNode());
SelectionUtil.selectCell(_context.getEditorContext(), _context.getNode(), SelectionManager.FIRST_ERROR_CELL + "|" + SelectionManager.FOCUS_POLICY_CELL + "|" + SelectionManager.FIRST_EDITABLE_CELL + "|" + SelectionManager.FIRST_CELL);
}
示例4: main
import java.awt.Robot; //导入方法依赖的package包/类
public static void main(String [] args) throws Exception {
Robot robot = new Robot();
SwingUtilities.invokeAndWait(() -> {
try {
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
throw new RuntimeException(e);
}
tf = new TestNimbusOverride();
tf.pack();
tf.setVisible(true);
});
robot.setAutoDelay(100);
robot.waitForIdle();
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyRelease(KeyEvent.VK_SPACE);
robot.waitForIdle();
SwingUtilities.invokeAndWait(() -> tf.dispose());
if (!passed) {
throw new RuntimeException(
"Setting Nimbus.Overrides property affects custom keymap installation");
}
}
示例5: writeString
import java.awt.Robot; //导入方法依赖的package包/类
private static void writeString(String s, Robot robot) throws InterruptedException {
for (char c : s.toCharArray()) {
if (isupper(c))
robot.keyPress(KeyEvent.VK_SHIFT);
if (c == ':') {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else {
robot.keyPress(Character.toUpperCase(c));
robot.keyRelease(Character.toUpperCase(c));
}
if (isupper(c))
robot.keyRelease(KeyEvent.VK_SHIFT);
Thread.sleep(15);
}
}
示例6: execute
import java.awt.Robot; //导入方法依赖的package包/类
@Override
public void execute(@NotNull String pattern) {
try {
Robot r = new Robot();
r.keyPress(157);
r.keyPress(90);
r.keyRelease(90);
r.keyRelease(157);
} catch (AWTException e) {
e.printStackTrace();
}
SelectionUtil.selectNode(_context.getEditorContext(), _context.getNode());
SelectionUtil.selectCell(_context.getEditorContext(), _context.getNode(), SelectionManager.FIRST_ERROR_CELL + "|" + SelectionManager.FOCUS_POLICY_CELL + "|" + SelectionManager.FIRST_EDITABLE_CELL + "|" + SelectionManager.FIRST_CELL);
}
示例7: main
import java.awt.Robot; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Test8013370 task = new Test8013370();
invokeAndWait(task);
Robot robot = new Robot();
robot.waitForIdle();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.waitForIdle();
invokeAndWait(task);
task.validate();
}
示例8: testFocus
import java.awt.Robot; //导入方法依赖的package包/类
static void testFocus() throws Exception {
System.out.println("Focus Test!");
Robot robot = new Robot();
robot.setAutoDelay(50);
Frame frame = new Frame();
frame.setSize(100, 100);
String test = "123";
TextField textField = new TextField(test);
textField.selectAll();
frame.add(textField);
frame.setVisible(true);
robot.waitForIdle();
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);
robot.keyPress(KeyEvent.VK_B);
robot.keyRelease(KeyEvent.VK_B);
robot.waitForIdle();
frame.dispose();
if (!textField.getText().equals("ab")) {
throw new RuntimeException("Focus is lost!");
}
}
示例9: execute
import java.awt.Robot; //导入方法依赖的package包/类
@Override
public void execute(@NotNull String pattern) {
try {
Robot r = new Robot();
r.keyPress(157);
r.keyPress(90);
r.keyRelease(90);
r.keyRelease(157);
} catch (AWTException e) {
e.printStackTrace();
}
SelectionUtil.selectNode(_context.getEditorContext(), _context.getNode());
SelectionUtil.selectCell(_context.getEditorContext(), _context.getNode(), SelectionManager.FIRST_ERROR_CELL + "|" + SelectionManager.FOCUS_POLICY_CELL + "|" + SelectionManager.FIRST_EDITABLE_CELL + "|" + SelectionManager.FIRST_CELL);
}
示例10: main
import java.awt.Robot; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
Frame frame = new Frame();
frame.setSize(300, 200);
TextField textField = new TextField();
frame.add(textField);
frame.setVisible(true);
toolkit.realSync();
textField.requestFocus();
toolkit.realSync();
// Check that the system assertion dialog does not block Java
Robot robot = new Robot();
robot.setAutoDelay(50);
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);
toolkit.realSync();
frame.setVisible(false);
frame.dispose();
}
示例11: pressKey
import java.awt.Robot; //导入方法依赖的package包/类
/**
* Using AWT robot presses and immediately releases certain key.
* @param code Code of the key to be pressed.
*/
private void pressKey(int code) {
try {
Robot robot = new Robot();
robot.keyPress(code);
robot.keyRelease(code);
} catch (AWTException ex) {
Exceptions.printStackTrace(ex);
}
}
示例12: robotKeyPressTest
import java.awt.Robot; //导入方法依赖的package包/类
public void robotKeyPressTest() throws Exception {
SwingUtilities.invokeAndWait(() -> {
frame = new Frame();
frame.setSize(300, 300);
frame.setVisible(true);
});
Robot robot = new Robot();
robot.waitForIdle();
Point pt = frame.getLocationOnScreen();
robot.mouseMove(((int) pt.getX() + frame.getWidth()) / 2,
((int) pt.getY() + frame.getHeight()) / 2);
robot.waitForIdle();
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.waitForIdle();
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.waitForIdle();
robot.keyPress(KeyEvent.VK_ENTER);
robot.waitForIdle();
robot.keyRelease(KeyEvent.VK_ENTER);
robot.waitForIdle();
SwingUtilities.invokeAndWait(() -> {
frame.dispose();
});
}
示例13: find
import java.awt.Robot; //导入方法依赖的package包/类
public static void find(String text,Robot robot) {
Find op=new Find();
robot.waitForIdle();
java.awt.Point p=op.cboFindWhat().getLocationOnScreen();
int x=p.x+op.cboFindWhat().getWidth()/2;
int y=p.y+op.cboFindWhat().getHeight()/2;
robot.mouseMove(x,y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(50);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
char c;
boolean upper;
for (int i=0;i < text.length();i++) {
c=text.charAt(i);
if (Character.isUpperCase(c)) {
upper=true;
} else {
upper=false;
c=(char)(Character.toUpperCase((char)c));
}
if (upper) {
robot.keyPress(KeyEvent.VK_SHIFT);
}
robot.keyPress((int)c);
robot.delay(5);
robot.keyRelease((int)c);
robot.delay(5);
if (upper) {
robot.keyRelease(KeyEvent.VK_SHIFT);
}
}
p=op.btFind().getLocationOnScreen();
x=p.x+op.btFind().getWidth()/2;
y=p.y+op.btFind().getHeight()/2;
robot.mouseMove(x,y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(50);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(50);
robot.waitForIdle();
}
示例14: TestPopupMenu
import java.awt.Robot; //导入方法依赖的package包/类
public TestPopupMenu() throws Exception {
Robot robot = new Robot();
robot.setAutoDelay(200);
try {
SwingUtilities.invokeAndWait(() -> {
try {
createAndShowUI();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
});
blockTillDisplayed(label);
robot.waitForIdle();
robot.mouseMove(p.x + d.width/2, p.y + d.height/2);
robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
robot.waitForIdle();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_U);
robot.keyRelease(KeyEvent.VK_U);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.waitForIdle();
JPopupMenu popup = label.getComponentPopupMenu();
if (popup != null && popup.isVisible()) {
throw new RuntimeException("Popup is visible in wrong internal frame");
}
} finally {
SwingUtilities.invokeAndWait(()->frame.dispose());
}
}
示例15: test
import java.awt.Robot; //导入方法依赖的package包/类
private static void test(final int key) throws Exception {
passed = false;
try {
SwingUtilities.invokeAndWait(() -> {
frame = new JFrame();
JComboBox<String> combo = new JComboBox<>(new String[]{"one", "two", "three"});
JPanel panel = new JPanel();
panel.add(combo);
combo.requestFocusInWindow();
frame.setBounds(100, 150, 300, 100);
addAction(panel, key);
frame.add(panel);
frame.setVisible(true);
});
Robot robot = new Robot();
robot.waitForIdle();
((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
robot.keyPress(key);
robot.waitForIdle();
((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
robot.keyRelease(key);
robot.waitForIdle();
((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
if (!passed) {
throw new RuntimeException("FAILED: " + KeyEvent.getKeyText(key) + " was consumed by combo box");
}
} finally {
if (frame != null) {
frame.dispose();
}
}
}