Link to home
Start Free TrialLog in
Avatar of Lucky3664
Lucky3664

asked on

Barcode reader

Hi
 I want to redirect barcode reader output to a specific edit. But Barcode reader is not provide the data from a COM, it behaves like keyboard.
How can I do that?
Thanks..
Avatar of Member_2_4694817
Member_2_4694817

You may try to watch the keyboard and whenever data seems to come from the barcode reader (many digits in less time than one could type), redirect the focus to the specific edit.
Avatar of Lucky3664

ASKER

I am watching the keyboard with ApplicationMessage(var Msg: TMsg;var Handled: Boolean) procedure, but for example I have two edit box the first edit is for something and second edit box for barcode data, when the first edit box focused and at that time the barcode reader started wit my procedure (ApplicationMessage(var Msg: TMsg;var Handled: Boolean)) can I write the data to the second edit box
but at same time the first edit box has the same barcode data. So I should prevent the barcode data to go any component on the form..
ASKER CERTIFIED SOLUTION
Avatar of Member_2_4694817
Member_2_4694817

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The way you say is difficult for me. is not there any function or command to prevent barcode data to for that form. for example like KeyPreview property
Avatar of Geert G
get a different scanner, like a serial port scanner
and get some tool like
http://www.taltech.com/products/bcwedge.html
that's the easiest way !


or if possible configure the scanner to send a fixed key sequence
so you know it's the scanner entering data

otherwise the only options is the timer like thehagman noted
Thanks very much both of you.
Using serial port scanning, yes it is easy way. But it comes expensive for our customers nowadays.
The second way you say it is possible solution if the scanner is configureble. But for the way of thehagman I think also I need fixed key sequence because I get all data via (WM_CHAR,WM_KEYDOWN, WM_KEYUP) messages, so the barcode scanner that I have, behaves like keybord. I think should be something that I can distinguish where from the data comes, because  whether keyboard or usb barcode reader takes different root in device menager. But how can I do, I do not know.
i don't think you will be able to distinguish the difference
you will however get 10, 17, 20 or a certain length X from the barcode scanner

you could start a timer for the first keystroke and if you get like X keystrokes within the timer elaps time, then you have the barcode ...
don't think windows distinguishes between barcode scanner WM_CHAR and keyboard WM_CHAR
Most barcode readers can be programmed to send a leading character such as a hash (#) in front of the barcode.  If you attach a generic OnKeyDown event to the controls on your form that could have focus, you should be able to redirect focus to your desired Edit when you dectect the hash.
Hm, I understood very well. But I have an other problem now. The procedure that I use for this become to late geting messages.

procedure ApplicationMessage(var Msg: TMsg;var Handled: Boolean);
begin
   case Msg.Message of
    WM_CHAR:
    begin
      if ToAsciiEx(Msg.wParam,MapVirtualKeyEx(Msg.wParam,2,1),KeyState,@LastKey,0,1)>0 then
      begin
         Key:=Ord(LastKey);
         BarcodeString := BarcodeString + IntToAscii(Key);
      end;
    end;
    WM_KEYDOWN, WM_KEYUP:
    case Msg.wParam of
    VK_RETURN:
      begin
       if BarcodeString <> '' then
       begin
           Edit2.SetFocus;
           Edit2.Text := BarcodeString;
           BarcodeString := '';
       end;
      end;
     end;
    end;
end;
 I use this procedure to get the barcode data, but when I push the button on barcode reader it gives me the data before my procedure. So I could not find a solution for this again. I think it will be difficult for me.
i don't follow ... how do you get the data ?
what data and in what procedure (or object) ?
the procedure ApplicationMessage(var Msg: TMsg;var Handled: Boolean) works behind self when form is created. I say only  Application.OnMessage := ApplicationMessage; . Then I handel the message VM_CHAR. When I get #13 wparam (VK_RETURN) it automatically goes on  WM_KEYDOWN, WM_KEYUP: and then write the barcodestring to edit2;

um ? this english looks a lot like chinese to me ... i have no clue what you are on about !
Sorry about my english.
The procedure that I send is working and I will do it again such before  thehagman and you said, so using timer and bufferin data. But in this case I should find a way to prevent the barcode reader comes before my procedure, because I noted that the procedure that I use comes to late to focusing related edit or doing something .