Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi,

i need to create POS window in my C# application ..now i created all thing , only one thing i want to do :
i want to search for barcode without having textbox .. so i can get the barcode after barcode reader read it if gridview or any other control was focused ..

so what is the event which fired when barcode reader begin reading the code ?

What I have tried:

i tried to search about that but i can't find any Clear answers
Posted
Updated 6-Mar-19 22:01pm

Handle the global keyboard input on your form like this :
C#
private string _barcode = "";
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
     char c = (char)keyData;

     if (char.IsNumber(c))
         _barcode += c;

     if (c == (char)Keys.Return)
     {
         DoSomethingWithBarcode(_barcode);
         _barcode="";
     }

     return base.ProcessCmdKey(ref msg, keyData);
}
and do what you need with the barcode value in DoSomethingWithBarcode() method.
 
Share this answer
 
v2
Comments
Golden Basim 7-Mar-19 4:11am    
thank you for your answer... i want to know how to run "ProcessCmdKey" whene my barcode reader begin to work ? which event i can to use ?

thanks
Mehdi Gholam 7-Mar-19 4:20am    
You don't run ProcessCmdKey(), it will always run on a key input like an event listener.
Golden Basim 7-Mar-19 4:58am    
thank you , it work but why i make it accept character and symbols like (-,/,.,...) not just number ..
i tried to scan this code (3PZ.55.24861456.17) but the result was ( 33PZ¾55¾24861456¾17)
Mehdi Gholam 7-Mar-19 5:21am    
You can comment the if statement which checks for numbers only.
Golden Basim 7-Mar-19 5:36am    
i did that but it read ENTER key within the code so like that :
this code " 4063717659543
" does not exist!
The problem is that most barcode scanners ship configured to act as a keyboard, which gives two problems:
1) You can't tell the difference between "real" keyboard data and "genuine barcode" keyboard data because the source of the data is not preserved by the system.
2) Because it's keyboard data, it is automatically routed to the currently active input control, and not to non-input controls.

You can normally set the scanner to provide "lead in" and "tail out" codes which let you differentiate keyboard from barcode data - though how you do that varies from scanner to scanner and even model to model, so you will need to check with the manufactureras to how you do that - which solves problem one.
It may also help solve problem two as well: by capturing the keyboard input at the form level (override ProcessCmdKey in your form to do this) and looking for your lead in and tail out sequences you can identify and process your barcode.
But ... think carefully before you do this: how often do you go to the supermarket and an operator has to manually enter barcode data because the item won't scan, the barcode is missing, the barcode is damaged? Using a textbox lets the operator enter the data as a backup system and is normally pretty necessary ...
 
Share this answer
 
v2
Comments
Golden Basim 7-Mar-19 9:42am    
thank you ..
i don't know why ProcessCmdKey don't read the code successfully ..

i tried to scan this code (3PZ.55.24861456.17) but the result was ( 33PZ¾55¾24861456¾17) ..

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