我怎样才能生成 1 只鼠标 + 1 次键盘点击?
我们正在为残疾人制作模拟器。我们目前正在测试此应用程序中有一个桌面区域。如何以编程方式生成 1 次鼠标单击,并在单击 1 次键盘后立即生成 1 次键盘单击?单击之间的时间为 100 毫秒。
编辑
这是您建议中的代码。
import java.awt.Robot;
import java.io.Console;
import javax.swing.Timer;
public class Start {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Timer timer = new Timer(100, new ActionListener() {
private final Robot robot = new Robot();
public void actionPerformed(ActionEvent evt) {
robot.mousePress(1);
robot.mouseRelease(1);
robot.keyPress(KeyEvent.VK_A);
robot.mouseMove(55, 145);
}
});
}
}
快照中显示有 5 个错误。
We are making an emulator for disabled persons. There is a desktop area in this app which we are testing at the moment. How can I programmatically generate 1 mouse click and immediately after it 1 keyboard click? Time between clicks is 100 ms.
EDIT
This is the code from your suggestions.
import java.awt.Robot;
import java.io.Console;
import javax.swing.Timer;
public class Start {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Timer timer = new Timer(100, new ActionListener() {
private final Robot robot = new Robot();
public void actionPerformed(ActionEvent evt) {
robot.mousePress(1);
robot.mouseRelease(1);
robot.keyPress(KeyEvent.VK_A);
robot.mouseMove(55, 145);
}
});
}
}
There are 5 errors which are shown in the snapshot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下
机器人
类,可用于以编程方式生成鼠标单击和键盘敲击。您可以将其与 SwingTimer 结合使用
类定期生成这些事件;例如Take a look at the
Robot
class, which can be used to programmatically generate mouse clicks and keyboard strokes. You could use this in conjunction with the SwingTimer
class to periodically generate these events; e.g.查看Robot 类。
Look at the Robot class.