0

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:

  1. Instantly disable the laptop keyboard and mouse (whenever required)
  2. Instantly enable them again (when needed)
  3. 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()
4
  • When you disable the device manually in the Windows device manager, does that do what you want? If yes, search for ways to do that programmatically. Commented May 6, 2021 at 5:01
  • 2
    If you have an external display you can go into power options and for "close the lid" check "do nothing". Then you can just close the lid and the cat can't sit on the keyboard. Commented May 6, 2021 at 5:10
  • @Tomalak Nope. Windows 10 continues using the device even though the drivers have been uninstalled (behavior exclusive to the laptop keypad). But this Python code works by disabling both keyboards. We just need to do it selectively for a particular driver. Commented May 6, 2021 at 13:56
  • @MichaelGuidry Wow! That's brilliant! Thanks for suggesting this. :) Commented May 6, 2021 at 13:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.