6

I am wondering how I can disable my keyboard and mouse in Python 3.7.1. This question was already asked many years ago here but the answers are for python 2.7. All the modules in the answers no longer work on Python 3.7.1.

I am asking as when I use pyautogui, I sometimes forget I cannot touch my keyboard/mouse. Thus, I want to disable my keyboard at at the parts I use pyautogui. Then enable the keyboard/mouse when it doesn't use pyautogui

Alex
  • 73
  • 7
  • Anybody got a solution? – Alex Apr 15 '19 at 23:40
  • `pyautogui` works by causing mouse events and keyboard events. It's not clear to me that you could disable keyboard/mouse input and still allow it to work. If you're using a USB keyboard you could try figuring out a way to disable and reenable USB. Keep in mind, too, that if your program hangs you could be left needing to power off your computer to fix it. – Nathan Vērzemnieks Apr 18 '19 at 01:02

1 Answers1

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)