如何在不使用java.awt.robot的情况下模拟mousePressed事件? [英] How can I simulate a mousePressed event without using java.awt.robot?
本文介绍了如何在不使用java.awt.robot的情况下模拟mousePressed事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Java中模拟mousePressed事件,发现可以为此使用Robot
类,并且它可以工作,但只能在Windows中,而不能在Mac OS X中使用.
I want to simulate a mousePressed event in Java, I found out that I can use the Robot
class for this, and it works, but only in Windows and not in Mac OS X.
有人知道模拟mousePressed
事件的另一种方法吗?
Does anyone know of an alternative way to simulate a mousePressed
event?
这是我使用的代码:
Robot robot = new Robot();
robot.mousePress(InputEvent.BUTTON1_MASK);
推荐答案
如果要模拟JButton
上的点击动作,可以调用doClick
方法,请查看类似的问题可以为您提供帮助.
希望这会有所帮助.
If you want to simulate the click action on a JButton
you can invoke the doClick
method, take a look here. Otherwise, maybe this similar question can help you.
Hope this helps.
这篇关于如何在不使用java.awt.robot的情况下模拟mousePressed事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文