0

I am using a Microsoft.NET text box in Windows Forms 2.0 using C# for data from a USB based Bar code scanner. The user does not want the text box to accept inputs from keyboard. How can i apply a filter such that only inputs from the USB are accepted and the keyboard disabled during this session ?

Thanks.

Comment added one hour after: I got some thing on this and this which i need to study.

To those of you who want to know why this redundancy, the user also wants an option to configure the Keyboard to be active / inactive .

Community
  • 1
  • 1
Chakra
  • 2,525
  • 8
  • 43
  • 82
  • 1
    If the box won't take keyboard characters then how are the scanner characters expected to get in seeing as how it *emulates a keyboard*? – Ignacio Vazquez-Abrams Dec 20 '10 at 05:31
  • You need to be more specific. Do you mean WinForms, WebForms, or WPF/Silverlight. (or GTK#, or Cocoa#, or MonoTouch/iOS, or Android/MonoDroid) – Jonathan Allen Dec 20 '10 at 05:33
  • Ok so it emulates a keyboard. However, is there a workaround to know where the inputs came from, and thereby filter only for USB ? – Chakra Dec 20 '10 at 05:33
  • 2
    @Chakra: What's wrong with allowing users to manually input characters via the keyboard in the event that they don't have a working USB barcode scanner? There's a reason why barcodes are usually printed with a human-readable number string representation somewhere next to it. – In silico Dec 20 '10 at 05:39
  • Maybe i should take a look at http://stackoverflow.com/questions/615036/reading-a-barcode-using-a-usb-barcode-scanner-along-with-ignoring-keyboard-data-i – Chakra Dec 20 '10 at 05:54
  • @Chakra - seems like a bit of a hack, but I suppose it would get the job done. I don't think I'd deploy that code, but whatever floats your boat. – Chase Florell Dec 20 '10 at 06:02

1 Answers1

5

You can't. The bar code scanner IS a keyboard (of sorts). It inputs text characters in the exact same way as a keyboard.

I suppose one option would be to disconnect the physical keyboard. And barring that, you could "try" to block input based on hardware serial number. But the problem with this is a) that it's not scalable, and b) if your scanner ever dies, you have to monkey with your software.

Also remember, bar codes are just line representations of human readable characters. That way you can enter the tiny numbers below the barcode manually if your scanner can't read them.

I'd push back and tell the boss that's a bad idea (depending on the context of the request of course).

Chase Florell
  • 46,378
  • 57
  • 186
  • 376