Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bar Code Scan event capture text

Tags:

c#

winforms

I have a win forms app that i am trying to add a bar code scan too.

The window has multi able text boxes which the user fills in. When user clicks on a box and scans bar code it goes into the selected text box.

Is it possible to write an event to put the text into a particular textbox when scanned even if a different text box is highlighted?

If so how would i do this. Thanks

like image 518
inkey Avatar asked Dec 28 '25 18:12

inkey


1 Answers

There are different types of barcode scanners: keyboard wedge, and serial ones.

Keyboard wedge will send 'messages' as if they were input from the keyboard. So normally they only appear when some kind of edit box has focus.

To put that scanned data in a textbox without having focus, the best and safest way would be to capture the messages in a seperate background thread (this could work for KB wedge as wel as for serial). With KB wedge, your thread would have to check the (prefix)codes to see if they are coming from the barcode scanner - if not, forward then to the normal windows message processing.

Some barcode scanners might have libraries available that already do that for you.

On the other hand, if the app has only one window, and a KB wedge scanner is used, a seperate thread could be avoided, and the messages can be captured inside that window, analysed, and if a barcode is detected the data can be put in the right text box. But I would never trust the user to be in the right text box when scanning the barcode - in fact, that text box should better be read-only.

But, in general, when the application has multiple windows, a background thread may be the only option. Some examples:

  • A user scans a barcode on a document (invoice for example), and that document needs to be opened automatically. The thread could capture the code, and open that document.

  • A user scans an EAN code, and wants to see the details of the product. Same as above.

like image 184
Danny_ds Avatar answered Dec 31 '25 07:12

Danny_ds



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!