Search code examples
javawindowsdevice-driver

Disable specific device when another device connects programatically


I have an issue where the keys on my Type Cover 2 on my Surface Pro 2 gets stuck after holding them down for 8 seconds. This is particularly annoying with to ctrl/shift/alt keys which often end up being held for a long time when editing images and so forth.

The solution to the problem is to disable "Microsoft Input Configuration Device" in Device Manager, however, it as well has some drawbacks, as most of the touchpad gestures will no longer worker.

I therefore thought I'd see if it's possible to automatically disable said device (or device driver) when I connect an external mouse, like a BlueTooth mouse or whatever, and then revert the effect whenever it would disconnect.

Is this a somewhat non-trivial task? If not, which programming language should I pursue my goal in? I've listed Java as a tag as it's my go-to language of choice.

Disclaimer: I wasn't 100 % percent certain whether to post this on stackoverflow or programmers, or even serverfault. I figured I'd try here as I'm after a programming solution.


Solution

  • You can do this via devcon - it's essentially a command line utility that allows you to control hardware (remove/disable/enable/rescan). The C source for this tool is in the WDK, so you could get it then wrap it in a DLL to use via JNA/I (or you could just make command line calls from Java to the devcon.exe itself).