mihail
mihail

Reputation: 2173

Detect input device type .NET

I'm writing a C# application in .NET 4. In the application I have 2 text boxes - one is used for user input, the other one is used for input from USB scanner. Is there some way to detect from which device the input comes - from keyboard or scanner (the scanner sends the characters from the barcode and Enter in the end). Is there any way to achieve this. So far I've tried to catch it in the text boxes onKeyDown onKeyPress triggers but without success. I get only the characters.

I guess I have to look somewhere in the reflection but I don't find anything since 3 days.

Thanks, Mihail

Upvotes: 2

Views: 1649

Answers (1)

akton
akton

Reputation: 14386

The barcode scanner will usually supply characters much faster than a human can type, usually every 10 milliseconds or so. An inelegant but effective solution is override OnKeyDown or OnKeyPress and, if the last event occurred a short time ago, treat it as a sequence of characters entered by the barcode scanner.

Upvotes: 3

Related Questions