使用以下代码将我的鼠标和键盘禁用10秒钟。代码运行时,我仍然可以移动鼠标和键盘。我也想从另一个脚本在python中调用此函数,但我不能。有什么建议吗?
import pythoncom, pyHook, time
start = time.time()
time.perf_counter
elapsed = 0
def windoow(event):
global elapsed
if elapsed < 10:
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()
答案 0 :(得分:0)
对我来说,只需两行编程即可解决问题:
from ctypes import *
ok = windll.user32.BlockInput(True) #enable block
#or
ok = windll.user32.BlockInput(False) #disable block