I know there are good articles and questions 开发者_C百科on installing keyboard hooks already, but I'm interested to know if and how it's possible to inspect the source device ID?
The idea would be to ignore any keyboard presses from the main keyboard, but hook any that come from a barcode scanner (which, if you didn't know, pretends to be a keyboard as far as the OS is concerned).
Check this article. It looks like it's not possible through keyboard hooks. He used the Raw Input API.
Raw Input (C# Example) can do this.
I had a play with that code with my own basic keyboard-wedge barcode scanner & found that in order to register events I needed to remove the if (rid.dwType == RIM_TYPEKEYBOARD || rid.dwType == RIM_TYPEHID)
filter so something needs tweaking.
If I did remove the restrictions it was successfully registering keyboard+scanner input and reporting different device details for each.
精彩评论