Texbox input, disable for keyboard, keep for barcode scanner

前端 未结 2 418
说谎
说谎 2021-01-28 19:07

I have made a Windows Form application with a textbox. I will force users to use the barcode scanner, so the keyboard input should be disabled. The KeyPressed event does not wor

相关标签:
2条回答
  • 2021-01-28 19:15

    You can find the way to check with keysUp and Keysdown event.

    Check here for detailed answer.

    Check here for answer

    Check here for github code

    0 讨论(0)
  • 2021-01-28 19:31

    Based on your description, I assume that your barcode scanner is an HID barcode scanner. If so, there is no easy answer here because the barcode scanner functions exactly like a keyboard. Disabling keyboard input will disable the barcode scanner.

    I have done this before, and there are a few solutions I know of:

    1. Use a barcode scanner that is not an HID barcode scanner. Ex: Serial, or something like that.
    2. Configure the barcode scanner to send a special character at the start and end of the barcode scan. (This is something you can do if you have the manual for the particular model of barcode scanner.) Write your KeyPressed event to listen for these special characters as a signal that it is getting data from the barcode scanner. When it sees them, enable and disable the text box.
    3. Use Windows API calls to communicate directly with the barcode scanner. This requires knowing the VID and PID of the barcode scanner, and some detailed knowledge of APIs like GetRawInputDeviceInfo, GetRawInputData, and RegisterRawInputDevices. This is very powerful, since you can receive barcode input from anywhere in the application, but it is very complex.

    However, one caveat: You probably don't want to disable the text box at all. What if the barcode is damaged and the scanner cannot read it? You always want the user to be able to manually enter the barcode. Next time you go through the cash register at a store, notice that there is always a way to manually enter the barcode.

    0 讨论(0)
提交回复
热议问题