Python Forum

Full Version: take over control of mouse/keyboard
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
My script periodically needs to control mouse/keyboard to do things for a few seconds then give the control back to user. This script just disable them, not what I want. Please advise. Thanks.


import pythoncom, pyHook 

def uMad(event):
    return False

hm = pyHook.HookManager()
hm.MouseAll = uMad
hm.KeyAll = uMad
hm.HookMouse()
hm.HookKeyboard()
pythoncom.PumpMessages()
Not sure this is what you're looking for, but think so

for keyboard see: https://pypi.org/project/keyboard/
for mouse see: https://pypi.org/project/mouse/