Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello guys, i have a situation where i would like to use barcode scanner exclusively using c#, i have a USB barcode scanner i want it to scan barcode behind the scene and print barcode anywhere the cursor is with some additional information with barcode.

Flow : barcode scanner scans barcode -> barcode gets searched in db to get info -> barcode + info gets printed in any active editor on screen.

For e.g.

DAP-11002233:testinformation

Hope i explained well.

thanks.

What I have tried:

i tried with low level keyboard hooks but it still prints barcode, also barcode is configured with enter key at the end but i am unable to manipulate it.
Posted
Updated 9-Aug-21 5:15am
Comments
Richard MacCutchan 9-Aug-21 9:07am    
"i want it to scan barcode behind the scene"
How would that work? A barcode scanner needs a human to point it at the barcode.
OriginalGriff 9-Aug-21 11:16am    
Not all of them - some sit there passively scanning 24/7 or are activated by a product breaking a photocell beam.
Richard MacCutchan 9-Aug-21 11:22am    
I doubt that the OP is using one of that type.

1 solution

The problem is that USB scanners are generally shipped set to emulate a keyboard - and once any character of the code has been received nothing in the system (including the operating system itself) has any idea if it was typed or scanned.

It may be possible to program the code reader to produce unique "lead in" and "tail out" sequences so that code can "recognise" a scanned code and divert it somewhere, but to do that you would need to write a global hook that intercepts the keyboard, looks for the lead in, code, tail out sequence and passes it to a specific application for processing. And those in C# are definitely not a job for the inexperienced as a single slip can crash out your whole computer. Develop these in a VM or get used to frequent reboots or even reinstalling the OS ... :laugh:

Chances are, you're overthinking your application and should reconsider exactly what you are trying to accomplish. Installing global hooks isn't easy on production machines, and is likely to become harder in future to reduce the impact of key loggers and such like.
 
Share this answer
 
Comments
Dave Kreskowiak 9-Aug-21 11:26am    
Global keyboard hook? Damn! I must have gone overboard when I did this 15 years ago, using nothing but the form's KeyPreview and KeyDown event.

...and the scanners ability to be told what lead-in and out sequences to use.
OriginalGriff 9-Aug-21 12:37pm    
That works, but only if the app is the active one.
The way I read the question, he's talking about "any active" on the screen - which means global hooking.
Dave Kreskowiak 9-Aug-21 13:06pm    
I was thinking more like the "background" of his app, but yeah.

He needs to be more specific.
Arsalan Khan 2 10-Aug-21 3:41am    
yes you are right i need the output in any active editor on screen, but with additional info with barcode, is there any way we can catch barcode scanner datarecieved event or something like that?
Dave Kreskowiak 10-Aug-21 9:28am    
If this is a "keyboard wedge" scanner there are no events. The scanner acts just like a normal keyboard, typing whatever code it scans. The only events you get are the normal keyboard events, KeyDown, KeyUp, KeyPressed. There is no way for you to tell the difference between what is typed at the keyboard and what is typed by the scanner.

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