我想制作一个应用程序,用于测量光标与组件中心的距离,然后将光标移回中心(与大多数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. 在TextArea中移动文本光标Java
- 2. 在VMware中移动光标
- 3. 在UITextView中移动光标
- 4. 在QTextEdit中移动光标
- 5. 将光标向下移动一行 - Java
- 6. 移动光标在崇高
- 7. TinyMCE移动光标
- 8. 光标不移动
- 9. UITextfield光标移动
- 10. 鼠标移动-crosshair光标
- 11. 移动鼠标光标Javascript
- 12. 迭代在PyMongo中移动光标?
- 13. 限制光标在UITextView中的移动
- 14. 光标在脸部中心移动?
- 15. 在textarea中移动光标以结束
- 16. 在c中移动光标位置#
- 17. 在contentEditable中移动光标位置div
- 18. 在窗口中移动光标 - ncurses
- 19. 如何在DataGridView中移动光标c#
- 20. 使光标在editText中不可移动
- 21. C#在游戏中移动光标
- 22. 在Atom中移动光标多行
- 23. 在屏幕上移动鼠标光标
- 24. Telerik RadEditor在拖动时移动光标
- 25. pyqt qtextedit移动光标
- 26. Emacs光标移动建议
- 27. 移动光标位置
- 28. UITextField光标向后移动
- 29. 移动光标上/下行
- 30. 将光标移动到CONTENTEDITABLE
谢谢您的打气!这当然做到了。 :3 – Supuhstar 2010-11-20 11:07:05