Click here to Skip to main content
15,793,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Barcode reader to read a barcode, it simply returns the text.
Barcode reader is interpreted as HID in windows,
I am using c# application to read the value.. I have to capture the value in a text box returned by Barcode scanner whether Textbox is having Focus or not.. Can you suggest how can it be done??
Also I am using TextChanged event which although is creating problem, when textbox recieves the input, event fires for each character in input,how can i first recieve whole input and then fire an event??

I want the application totally automatic so i am not using Click events or buttons to execute remaining operations...


Am I correct in understanding the barcode scanner acts like a second keyboard, in effect 'typing' the value of the barcode? How do you/do you need to distinguish between input on the keyboard and input from the scanner?

Next question is are you in WPF or WinForms? If its the latter, sounds like you want to intercept the keystrokes early on, at a form level. Are there other controls which accept keyboard input?

You can use something like this to capture all keystrokes at form level:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    if (msg.Msg == 0x100)
        // add to the string here
    return base.ProcessCmdKey(ref msg, keyData);
Share this answer
I use Mike O'Brien's HID Library[^]

This will allow you to capture the data from your barcode reader and process it in a class or on a form.

Most USB barcode readers default to the keyboard wedge and if the device supports HID then there is a programming barcode to change the device to use HID. If the device doesn't support HID then you are stuck with keyboard mode (or whatever mode it supports).
Share this answer
Barcode scanner by default act as a human input device, as you have noticed with yours. This allows them to work "straight out of the box" with many / most applications.

However, many of them are configurable to provide specific lead in / lead out codes to allow them to work in other ways. You will have to speak to the manufacturers if you want to enable this, as it will vary from manufacture to manufacturer - and possibly model to model.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900