Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to swallow a key in Raw Input?

I am using the Raw Input API because I need to be able to respond to keys from different USB HID devices differently, even if it is the same key.

My window receives the WM_INPUT messages correctly. I can retrieve the RAWKEYBOARD structure to obtain all the information I need.

Now I want to prevent those USB devices from being able to toggle NumLock. I am hoping that the Raw Input API might allow me to swallow the NumLock keypress?

I’ve tried setting the WM_INPUT message’s Result to 1, but that doesn’t seem to have an effect.

(I am writing this in C#, but since this is all low-level Windows API, you probably don’t need knowledge of C# or .NET to answer this.)

EDIT: Oh yeah, I’ve also tried using a global keyboard hook (SetWindowsHookEx) to swallow the NumLock keypress. Unfortunately, as soon as I initialize the Raw Input API, the global keyboard hook is no longer called while the window is active. I’ve also tried setting the global hook after the Raw Input one, but same effect.

like image 961
Timwi Avatar asked Nov 04 '22 04:11

Timwi


1 Answers

The Raw Input API does not support swallowing of keypresses.

Furthermore, it does not interact with SetWindowsHookEx within the same process. As soon as the Raw Input API is initialized, the hook is unhooked.

The solution is to have them in separate processes. One process can use SetWindowsHookEx to swallow the unwanted keys, while another uses the Raw Input API to process the keypresses that do come through. Then you just run both. This worked just fine for me.

like image 169
Timwi Avatar answered Dec 16 '22 11:12

Timwi