我想知道如何在Python 3.7.1
中禁用键盘和鼠标。这个问题已经在多年前here提出过,但是答案是针对python 2.7的。答案中的所有模块都不再适用于Python 3.7.1。
我问的是,当我使用pyautogui
时,有时会忘记无法触摸键盘/鼠标。因此,我想在使用pyautogui
的部分禁用键盘。然后在不使用pyautogui
答案 0 :(得分:0)
#Maybe ahk library can help you accomplish that python 3x for 2x try pyahk library
#Python 3x example, needs AHK installed.
import time
import ahk
from ahk import AHK, Hotkey
try:
ahk = AHK(executable_path="C:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe")
except:
ahk = AHK(executable_path="C:\\Program Files\\AutoHotkey\\AutoHotkeyU32.exe")
ahk.run_script('BlockInput, MouseMove')
time.sleep(5)
ahk.run_script('BlockInput, MouseMoveOff')
# you should be able to run it this way, did not test.
ahk_Script=['BlockInput, MouseMove', 'sleep 5000', 'BlockInput, MouseMoveOff']
for snipet in ahk_Script:
ahk.run_script(snipet, blocking=True)