I'd like to write an application which disables certain keys on the keyboard while it's working. More specifically I'm interested in keys that might make the application loose focus (like ALT+TAB, WinKey, Ctrl+Shift+Esc, etc.) The need for this is has to do with babies/animals bashing wildly at the keyboard. :)
My first idea was to use SetWindowsHookEx(), however I ran into a problem. Since I need a global hook, the procedure would have to reside in a .DLL which would get injected in all active applications. But a .DLL can be either 64-bit or 32-bit, not both. And on a 64-bit system there are both types of applications. I guess then that I must write two copies of the hook .DLL - one for 32-bit and the other for 64-bit. And then I'd开发者_如何转开发 also have to launch two copies of the application as well, because the application first has to load the DLL itself before it can pass it on to SetWindowsHookEx()
.
Sounds pretty clumsy and awkward. Is there perhaps a better way? Or maybe I've misunderstood something?
Note that I still want the mouse to work and "simple" alphabetic keys too, so BlockInput() will not do.
Added: I can develop both on .NET (C#/VB) or on C/C++ and WinAPI. I expect that the latter would be more appropriate.
WH_KEYBOARD_LL runs in the context of your process (On Win9x you will have to stick to the normal hook but you don't have the 64bit problem there)
精彩评论