0

I'm developing a application where user needs to get input from Barcode scanner. Its a usb type which scans and returns data in seconds.

I tried to stop getting input from Keyboard by many techniques

Made my textBox read only But failed to get input from reader

Managed keypress event But barcode reader actually acts as a Keyboard so i couldnt able to get required output

I need to Know is there any way to limit user with a particular time for providing input in textBox of windows forms or restrict user from providing input only from particular port?

I use code 128symbology for generating barcode.

emerson.marini
  • 9,331
  • 2
  • 29
  • 46
  • Welcome to SO. Why can't you read the input programmatically from the scanner and then set the `Text` property of the read-only `TextBox`? How do you bind it presently? – Patrice Gahide Feb 03 '15 at 09:34
  • You can do one thing, set the text box readonly property to true just before passing the usb value to text box after set it to false – Gun Feb 03 '15 at 09:43
  • 1
    Related: http://stackoverflow.com/questions/3655023/how-do-i-read-input-from-a-usb-hid-device – MarkU Feb 03 '15 at 10:19

1 Answers1

3

Related: How do I read input from a USB HID device?

Related article on CodeProject: http://www.codeproject.com/Articles/17123/Using-Raw-Input-from-C-to-handle-multiple-keyboard

Article on MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/ms645543(v=vs.85).aspx

This looks like a possible duplicate, but I'll summarize here to avoid link rot:

Since you indicate your barcode scanner is a USB device that behaves as an HID Keyboard, and you want your program's textbox to accept input from only this one particular device, you can use the HID Raw Input technique. However, this requires processing the raw HID reports from the device.

During initialization, your software registers for Raw Input from an HID input device having a specific Top Level Collection (TLC).

Use GetRawInputDeviceList to enumerate the available raw input devices, and use GetRawInputDeviceInfo to find each device's name. Within the name string you should be able to match the USB VID/PID values, so you can identify whether a keystroke message comes from the barcode scanner. Be sure to save the matching device handle hDevice discovered by this enumeration.

Extend your windowproc to handle WM_INPUT messages by GetMessage and GetRawInputData, and filter out messages from the standard keyboard by matching the raw input handle against the previously determined device handle of the barcode scanner.

Community
  • 1
  • 1
MarkU
  • 359
  • 2
  • 10