Right click on Python using ctypes

I am a complete newbie in Python, so I don't understand it. I want to use python to simply click on a specific point. I already managed to left click with 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 make a right click in the same way?

+7
source share
1 answer

Here are the constants 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 the code, you send two events: MOUSE_LEFTDOWN and MOUSE_LEFTUP . This simulates a "click".

Now for the right click you should send MOUSE_RIGHTDOWN and MOUSE_RIGHTUP same way.

+7
source

All Articles