I am a complete beginner to Python so dont understand the lingo. I want to use python to do a simple click at a specific point. I have already managed a left click using ctypes:
>>> import ctypes
>>> ctypes.windll.user32.SetCursorPos(x,y), ctypes.windll.user32.mouse_event(2,0,0,0,0), ctypes.windll.user32.mouse_event(4,0,0,0,0)
is there a way to do a right click in the same way?
Here are the constants that you would use for mouse_event
MOUSE_LEFTDOWN = 0x0002     # left button down 
MOUSE_LEFTUP = 0x0004       # left button up 
MOUSE_RIGHTDOWN = 0x0008    # right button down 
MOUSE_RIGHTUP = 0x0010      # right button up 
MOUSE_MIDDLEDOWN = 0x0020   # middle button down 
MOUSE_MIDDLEUP = 0x0040     # middle button up 
In your code you are sending two events: MOUSE_LEFTDOWN and MOUSE_LEFTUP. That simulates a "click".
Now for a right click you would send MOUSE_RIGHTDOWN and MOUSE_RIGHTUP in a similar fashion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With