开发者

Win32: Get device info in WH_KEYBOARD_LL || Block input on WM_INPUT when using Raw Input

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


@Hans Passant: WH_KEYBOARD_LL is a global only hook, which can be set up in C#


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.


@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 :/


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:

  • An application does not have to detect or open the input device.
  • An application gets the data directly from the device, and processes the data for its needs.
  • An application can distinguish the source of the input even if it is from the same type of device. For example, two mouse devices.
  • An application manages the data traffic by specifying data from a collection of devices or only specific device types.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜