I'm making an application to run in the background on a salespoint to read input from a usb scanner. How can I get the input of the scanner from C#? And can I differentiate between the scanner and a usb keyboard? (Scanner is a HID device)
Asked
Active
Viewed 4.0k times
1 Answers
13
I did this successfully before using a “Raw Input” implementation on CodeProject:
It allows you to receive both the input (what “keys” are pressed if it mimics a “keyboard”) as well distinguish which device it came from.

Timwi
- 65,159
- 33
- 165
- 230
-
That looks pretty good. However it doesnt seem to be firing the _KeyPressed event even though it picked up my 2 HID devices. – dkarzon Sep 07 '10 at 03:55
-
Got it working, was compiling it under 32 bit on a 64 bit Windows. Thanks again. – dkarzon Sep 07 '10 at 04:41
-
I'm using RawInput to get the keypress from a specific keyboard, and that works fine, except that it still sends the original keypress. So if I map {Backspace} to be Control-C, and then press Backspace, it first executes a backspace and then executes the Control-C. I'm trying to get it to (obviously) only do the Control-C (Macro) and not the Backspace (original keypress). Any ideas on how to do that? I've heard it requires Keyboard Hooks to cancel the message, Raw Input to determine if it's from the right keyboard, and a communication system, between the two. – Tanoshimi Feb 18 '16 at 17:42
-
linux like solution is possible ? – riccardo airone Dec 08 '16 at 12:22
-
This project is under LGPL v3 license ;( – OneWorld Jul 19 '17 at 08:01
-
if anyone interested - I just downloaded source `Download rawinput_latest.zip - 106.4 KB` - it works in VS 2022 with .NET Framework 4.8 with USB and PS/2 keyboards connected at the same time. – Boppity Bop May 14 '22 at 10:05