Mouse right button click

1119 views python

How can I make in python that after I run a script and press for example F11 click event of right mouse button starts and continues that it would be same as holding right mouse button?

answered question

If you do a few quick searches on this title alone, you'll be getting numerous hits on how to do this very thing.

1 Answer


I would use pyautogui for the mouse control and pyHooks to continue to monitor for specific keys to be pressed.

import pythoncom, pyHook
import pyautogui as pag

def OnKeyboardEvent(event):

    if event.KeyID == 122:  # "F11 Key"
        pag.mouseDown(button='right')  # press the right button down
        pag.mouseUp(button = 'right') # This will release the right button in case you want it

    return True

if __name__ == '__main__':

    hm = pyHook.HookManager()
    # watch for all keyboard events
    hm.KeyDown = OnKeyboardEvent
    # set the hook
    # wait forever

posted this

Have an answer?


Please login first before posting an answer.