使用Java发送组合键 [英] Using Java to send key combinations
本文介绍了使用Java发送组合键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按本previous链接(如何发送键盘输出) Java可以模拟使用机器人类pssed一个键为$ p $。但是,怎么可能键presses的组合来模拟?如果我想给组合ALT-123采用机器人将这种可能呢?
As per this previous link (How to send keyboard outputs) Java can simulate a key being pressed using the Robot class. However, how could a combination of key presses be simulated? If I wanted to send the combination "alt-123" would this be possible using Robot?
推荐答案
简单的答案是肯定的。基本上,你需要换行键preSS /发布
的<大骨节病>替代骨节病>周围的其他键$ P $的PSS /发布
取值
The simple answer is yes. Basically, you need to wrap the keyPress/Release
of the Alt around the other keyPress/Release
s
public class TestRobotKeys {
private Robot robot;
public static void main(String[] args) {
new TestRobotKeys();
}
public TestRobotKeys() {
try {
robot = new Robot();
robot.setAutoDelay(250);
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_1);
robot.keyRelease(KeyEvent.VK_1);
robot.keyPress(KeyEvent.VK_2);
robot.keyRelease(KeyEvent.VK_2);
robot.keyPress(KeyEvent.VK_3);
robot.keyRelease(KeyEvent.VK_4);
robot.keyRelease(KeyEvent.VK_ALT);
} catch (AWTException ex) {
ex.printStackTrace();
}
}
}
这篇关于使用Java发送组合键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文