My cat keeps sitting on my laptop keyboard while I"m working. I use a USB keyboard/USB mouse and I want to disable only the laptop keyboard/touchpad. So what I want to do is this:
- Instantly disable the laptop keyboard and mouse (whenever required)
- Instantly enable them again (when needed)
- Not have to restart the system for either changes
I have searched extensively for an answer to this and I've found no easy working solutions. All of them require a restart on windows 10 and they're extremely painful. Here are a few examples (and also reasons why this question is NOT a duplicate):
disable or lock mouse and keyboard in Python?
You're basically disabling EVERYTHING! Even the USB keyboard. There's no specific way of disabling on selected drivers.
Here's another option: Python Block Keyboard / Mouse Input
Again we're disabling EVERYTHING! How do we work if we disable both keyboards?
Here's another option: https://superuser.com/questions/346570/how-can-i-disable-my-laptops-built-in-keyboard-in-windows-7
Here the idea of using group policy to disable "all automatic driver installations" is an obvious overkill IMO! After a couple of weeks there will come a time when you need this and you'll be stuck trying to recall how to enable this. It also needs a restart.
All other answers on this page require you to restart your PC.
Question:
Is there a way in Python that can specify a particular driver and capture all input from it? Maybe we can modify this code so it works only on a particular device driver?
import pythoncom, pyHook
def uMad(event):
return False
hm = pyHook.HookManager()
hm.MouseAll = uMad
hm.KeyAll = uMad
hm.HookMouse()
hm.HookKeyboard()
pythoncom.PumpMessages()