Winforms disabling keyboard input on textbox but keeping textbox enabled

.net, c#, winforms

Solution

You said you'll need to support any barcode reader, which usually emulate a keyboard, therefore there probably isn't an easy way to programmatically distinguish between input from a keyboard and a barcode reader.

Your idea about using timing is a good one, although I'd do something slightly differently. I'd add a `Timer` to the `Form` and start it when the first character is entered into the `TextBox`. The timer should be set to a very short time span and should have auto-restart disabled. When the timer goes off, check if the `TextBox` has a valid barcode, and if does, process it. Either way, clear the text box afterwards.

It would then appear to anyone attempting to use the keyboard that their typed text simply disappears, while a barcode scanner (which 'types' very fast) would still work.

Problem

The scenario is like that; I need to disable textbox to take input from user by keyboard. But textbox should take inputs using kind of devices like barcode reader. I thought to hold a timer and take the timespan between two key strokes (not clear yet). But maybe there is a property or smarter algorithm for that ? p.s. it is a windows forms application.

Original source