How to click on a coordinate on a screen?

断了今生、忘了曾经 提交于 2019-12-24 18:21:24

问题


I have a program that wants to be able to click on the screen; say my screen is X by Y pixels, I want to make my program send clicks to coordinate (x, y). Any language is acceptable, but preferably Ruby, Java, or Python :)

Preferably on Windows, Ubuntu is another possibility.

Thanks for the help.


回答1:


With Ubuntu:

from Xlib import X, display

disp = display.Display()
screen = disp.screen()
root = screen.root
root.warp_pointer(300, 300)
disp.sync()

So as a function:

from Xlib import X, display

def MoveMouse(x, y):
  disp = display.Display()
  screen = disp.screen()
  root = screen.root
  root.warp_pointer(x, y)
  disp.sync()

I'll edit in click functionality in a little bit...


Holy cow, just look at the help(root)! You can draw things, change the cursor, fiddle with windows, and kill X!

I'm using this for my own purposes...




回答2:


I would give a short answer to your question, but I believe that this article here explains things a lot better than I would and would be much more beneficial. It's in Java and goes over the Robot class which is good for input simulations, mainly for things such as tech demos where the robot class substitutes for real user input. It's fairly in depth, short, and is a really easy read. Hope you enjoy!



来源:https://stackoverflow.com/questions/5672286/how-to-click-on-a-coordinate-on-a-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!