[英]Python: Using timer with PyHook
I am attempting to use PyHook to disable keyboard and mouse while running the script, and I am having difficulties setting a timer function so that the keyboard and mouse will only be disabled for a predefined amount of time, eg 30 seconds, and then return to normal. 我试图在运行脚本时使用PyHook禁用键盘和鼠标,并且在设置计时器功能时遇到困难,因此只能在预定义的时间(例如30秒)内禁用键盘和鼠标,然后返回到正常。
def windoow(event):
while True:
return False
time.sleep(30)
break
hm = pyHook.HookManager()
hm.MouseAll = windoow
hm.KeyAll = windoow
hm.HookMouse()
hm.HookKeyboard()
pythoncom.PumpMessages()
I am new to programming in general, and I am therefore hoping for an easy solution that I can learn from and understand. 我是编程的新手,因此我希望有一个简单的解决方案,让我可以学习和理解。
Thank you. 谢谢。
Hmm, This is pretty nefarious but this does work. 嗯,这很恶毒,但是确实有效。 Your time.sleep() was never executing because it was placed after a return statement 您的time.sleep()从未执行过,因为它被放置在return语句之后
import pythoncom, pyHook, time
start = time.time()
time.clock()
elapsed = 0
def windoow(event):
global elapsed
if elapsed < 30:
elapsed = time.time() - start
time.sleep(1)
return False
return True
hm = pyHook.HookManager()
hm.MouseAll = windoow
hm.KeyAll = windoow
hm.HookMouse()
hm.HookKeyboard()
pythoncom.PumpMessages()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.