问题
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 .
回答1:
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).
来源:https://stackoverflow.com/questions/4487153/how-can-i-filter-a-microsoft-net-2-0-text-box-to-only-take-usb-characters