Reputation: 21
I need to write a program to modify the input of a certain usb hid keyboard (barcode scanner) under Windows. The following workflow should apply:
Listen to input from device -> record input -> stop input from getting to the active application -> process recorded input and output result to active application
So I did search for this but now I'm stuck!
There are obviously two options for "record input": the low level hook WH_KEYBOARD_LL and reacting to WM_INPUT event in Raw Input
Problem is: - with WH_KEYBOARD_LL I found no way to determine from which device the input came - in the WM_INPUT event I found no way to stop the keystroke - if WH_KEYBOARD_LL is used to stop the keystroke it won't get to Raw Input thus not triggering WM_INPUT and so I can't determine the source of the keystroke
What are my options in user mode?
Regards, Dominik
Upvotes: 2
Views: 3149
Reputation: 415
I believe RAWINPUT is your best option, This is what Microsoft has to say about it.
The raw input model is different from the original Windows input model for the keyboard and mouse. In the original input model, an application receives device-independent input in the form of messages that are sent or posted to its windows, such as WM_CHAR, WM_MOUSEMOVE, and WM_APPCOMMAND. In contrast, for raw input, an application must register the devices it wants to get data from. Also, the application gets the raw input through the WM_INPUT message.
There are several advantages to the raw input model:
HID devices can be used as they become available in the marketplace, without waiting for new message types or an updated OS to have new commands in WM_APPCOMMAND.
You can research it here
Also I have an example here
Upvotes: -1
Reputation: 172
@Michael: It seems that WM_INPUT occurs after the hook, that's the problem...
PS: Sorry for not using comments... I just decided to create an account after posting this question, so I can't even comment my OP or any answers except for my own :/
Upvotes: 1
Reputation: 9068
Sadly there is no easy way to do that. You're with your WH_KEYBOARD_LL
and WM_INPUT
. There might be a chance of an option though:
Have you tested whether WM_INPUT
occurs before the hook? If that was the case, you could remember the characters from WM_INPUT
and -- in the hook -- remove only those characters that came from your barcode scanner.
Upvotes: 1
Reputation: 172
@Hans Passant: WH_KEYBOARD_LL is a global only hook, which can be set up in C#
Upvotes: 1