我想製作一個應用程序,用於測量光標與組件中心的距離,然後將光標移回中心(與大多數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