如何在Python 3.7.1中禁用然后重新启用键盘/鼠标

时间:2019-04-15 00:37:43

标签: python python-3.x

我想知道如何在Python 3.7.1中禁用键盘和鼠标。这个问题已经在多年前here提出过,但是答案是针对python 2.7的。答案中的所有模块都不再适用于Python 3.7.1。

我问的是,当我使用pyautogui时,有时会忘记无法触摸键盘/鼠标。因此,我想在使用pyautogui的部分禁用键盘。然后在不使用pyautogui

时启用键盘/鼠标

1 个答案:

答案 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)