Colin Is Awsum
Colin Is Awsum

Reputation: 9

Right Click simulate on python

I'm using python 2.7 in windows and I need to be able to code a right click at a certain xy coordinate. I already have the left click capability using this:

def click(x,y):
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

Any similar/completely different way to code a right click xy dependant function?

Upvotes: 0

Views: 4239

Answers (2)

ors
ors

Reputation: 101

from this link: mouse_even function on MSDN

looks like you can replace

MOUSEEVENTF_LEFTDOWN -> MOUSEEVENTF_RIGHTDOWN

MOUSEEVENTF_LEFTUP -> MOUSEEVENTF_RIGHTUP

Upvotes: 0

halex
halex

Reputation: 16403

Use win32con.MOUSEEVENTF_RIGHTDOWN and win32con.MOUSEEVENTF_RIGHTUP as the first argument for the respective calls to mouse_event. If this change alone does not help it can be beneficial when inserting a short pause between the mouse down and up with time.sleep(0.05)

Upvotes: 1

Related Questions