使用以下代码禁用我的鼠标和键盘 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()
最佳答案
对我来说,只需两行编程就解决了问题:
from ctypes import *
ok = windll.user32.BlockInput(True) #enable block
#or
ok = windll.user32.BlockInput(False) #disable block
关于python - 禁用鼠标功能Python代码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57113002/