How do I set the position of the mouse in Java?

后端 未结 5 1569
-上瘾入骨i
-上瘾入骨i 2020-12-15 19:32

I\'m doing some Swing GUI work with Java, and I think my question is fairly straightforward; How does one set the position of the mouse?

5条回答
  •  心在旅途
    2020-12-15 19:49

    You need to use Robot

    This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed. The primary purpose of Robot is to facilitate automated testing of Java platform implementations.

    Using the class to generate input events differs from posting events to the AWT event queue or AWT components in that the events are generated in the platform's native input queue. For example, Robot.mouseMove will actually move the mouse cursor instead of just generating mouse move events...

提交回复
热议问题