Search code examples
c#wpfkeyboard-hooksmartcard-readerkeyboard-wedge

High level global keyboard hook for C# and WPF for reading a keyboard wedge card scanner


The only keyboard hook supported for .NET managed code is a low-level keyboard hook (WH_KEYBOARD_LL).

See Using global keyboard hook (WH_KEYBOARD_LL) in WPF / C#

I have the above code working in my application at the moment so that when you swipe your card you will get a list of all the keystrokes. The problem is for typing delimiter characters such as "%" and ";" it will send me Alt+Numpad+? WPF Key objects corresponding to these symbols.

My question: Is there some way to make this behave more high-level, that is, to capture a string generated from all keyboard commands?

Cheers!


Solution

  • Not sure what's going on, but getting a character like % out of a keyboard hook is very untrivial. The hook only notifies you of virtual keys. But % is a typing key, produced by pressing Shift + 5 on my keyboard (a US layout). Windows normally produces these characters by processing the WM_KEYDOWN/UP messages, generating a WM_CHAR message for the typing key. That's not happening in your case. The low-level Windows function that does this is ToUnicodeEx().