Record second keyboard events

I have my own keyboard and a USB barcode scanner that works like a second keyboard.

I would like to use the main keyboard to control the computer (as you usually do), and the second keyboard (actually this is a barcode scanner) to register all the input to the file.

Can this be done?

The fact is that I can be on the Internet, a word, succeed or something else. I would use the main keyboard to write to these processes, while in the background a second keyboard (barcode scanner) could be written simultaneously, but to a log file. The program that I could use at the moment will never know about the second keyboard input.

enter image description here

Thank you, all suggestions are welcome.

+5
source share
1 answer

You can use the Raw Input API to monitor keyboard events before the OS processes them. The API will tell you which device sends each event, so you can only log events from the scanner.

However, the Raw Input API does not allow you to block input, so to block scan events from being processed as regular keyboard events, you will need to use SetWindowsHookEx() to set up a keyboard hook that rejects events.

However, SetWindowsHookEx() does not tell which device is sending each event, so you will need to coordinate the two APIs manually. When Raw Input detects a keyboard event, set the flag based on which the event occurred. When the hook detects a bypass event, check the flag and release the event if the flag points to the scanner device.

See Combining Raw Input and Hook Keyboards for selectively blocking the input of multiple keyboards in CodeProject.

+1
source

Source: https://habr.com/ru/post/1264325/