我想制作一个应用程序,用于测量光标与组件中心的距离,然后将光标移回中心(与大多数PC视频游戏一样)。有没有人有什么建议?在Java中移动光标
18
A
回答
29
机器人类可以为你做的伎俩。这里是移动鼠标光标的示例代码:
try {
// These coordinates are screen coordinates
int xCoord = 500;
int yCoord = 500;
// Move the cursor
Robot robot = new Robot();
robot.mouseMove(xCoord, yCoord);
} catch (AWTException e) {
}
3
嗨,这将只是增加。我使用Raspberry PI很多,所以我不得不学习如何优化我的代码,这会缩短很多。
try {
//moves mouse to the middle of the screen
new Robot().mouseMove((int) Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2, (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight()/2);
//remember to use try-catch block (always, and remember to delete this)
} catch (AWTException e) {
e.printStackTrace();
}
不要忘记导入:
import java.awt.*;
相关问题
- 1. 在UITextView中移动光标
- 2. 在QTextEdit中移动光标
- 3. TinyMCE移动光标
- 4. 光标不移动
- 5. UITextfield光标移动
- 6. 移动鼠标光标Javascript
- 7. 鼠标移动-crosshair光标
- 8. 在c中移动光标位置#
- 9. 迭代在PyMongo中移动光标?
- 10. 使光标在editText中不可移动
- 11. 如何在DataGridView中移动光标c#
- 12. 光标在脸部中心移动?
- 13. 在Atom中移动光标多行
- 14. 在窗口中移动光标 - ncurses
- 15. C#在游戏中移动光标
- 16. 移动光标被列
- 17. Emacs光标移动建议
- 18. 如何移动editText光标?
- 19. 如何移动光标在硒的webdriver
- 20. 在不移动光标时更改
- 21. 在密码输入光标移动C++ \
- 22. 物理移动光标在Python
- 23. iPad上的UITextView中的光标移动
- 24. 使用鼠标光标移动对象 - Java
- 25. 根据鼠标光标移动图像
- 26. 鼠标滚轮移动光标
- 27. 改变鼠标移动光标类型
- 28. Visual Studio - 滚动并移动光标
- 29. 如何在不移动光标的情况下移动屏幕?
- 30. 锁定鼠标光标只在一个控件中移动
谢谢您的打气!这当然做到了。 :3 – Supuhstar 2010-11-20 11:07:05