cyracks Posted December 14, 2022 Share Posted December 14, 2022 Hello. I created a program for barcode readers, but I have a problem with a scanner. As you know barcode reader is similar to regular phone, but it has a scanner that can act as keyboard, which can be set to Physical or Virtual mode. In app I have set TForm.KeyPreview = True and event TForm.UniFormKeyPress is saving what scanner is reading (or user is typing). But there are two problems: - on local computer everything works fast and ok but when used on mobile phone with remote server it is much much slower. The problem is that Form.UniFormKeyPress is handled by server so for every key press request to server is made and it can take up to 3-4 seconds to process 13 char long barcode. That of course is unbearable if you would like to quickly scan barcodes. - if scanner is set to use Virtual keyboard Unigui is not catching pressed keys (I tried with different scaners) I think solution si to catch key events on client side, setting is in TForm.ClientEvents.ExtEvents->Ext.form.Panel event Form.KeyPress But I would need help 1) How do I save pressed keys on client side into a string function form.keypress(sender, key, eOpts) { // what is in here } 2) When enter is pressed how to send that string to server to be processed. Is there any other better solution ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 15, 2022 Share Posted December 15, 2022 Hello, Are you using the device!? If yes, then I don't know how you connect the device, how it works... Although the forum has a few examples of using the phone's camera... Quote Link to comment Share on other sites More sharing options...
cyracks Posted December 15, 2022 Author Share Posted December 15, 2022 Barcode reader is similar to a phone, with the exception of having scanner attached that act like keyboard. It runs android so unigui app can be opened in a web browser (or TWebBrowser inside FMX app). Link to google that shows what I mean So no Phone camera is needed since scanner acts as keyboard and web browser can be used. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 15, 2022 Share Posted December 15, 2022 6 minutes ago, cyracks said: So no Phone camera is needed since scanner acts as keyboard in web browser can be used. 6 minutes ago, cyracks said: TWebBrowser inside FMX app Then, it's even easier I guess. Quote Link to comment Share on other sites More sharing options...
cyracks Posted December 15, 2022 Author Share Posted December 15, 2022 5 minutes ago, Sherzod said: Then, it's even easier I guess. Do you maybe know an answer to my question ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 15, 2022 Share Posted December 15, 2022 3 minutes ago, cyracks said: Do you maybe know an answer to my question ? Sorry, no at the moment. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 15, 2022 Share Posted December 15, 2022 11 hours ago, cyracks said: Hello. I created a program for barcode readers, but I have a problem with a scanner. As you know barcode reader is similar to regular phone, but it has a scanner that can act as keyboard, which can be set to Physical or Virtual mode. In app I have set TForm.KeyPreview = True and event TForm.UniFormKeyPress is saving what scanner is reading (or user is typing). But there are two problems: - on local computer everything works fast and ok but when used on mobile phone with remote server it is much much slower. The problem is that Form.UniFormKeyPress is handled by server so for every key press request to server is made and it can take up to 3-4 seconds to process 13 char long barcode. That of course is unbearable if you would like to quickly scan barcodes. - if scanner is set to use Virtual keyboard Unigui is not catching pressed keys (I tried with different scaners) I think solution si to catch key events on client side, setting is in TForm.ClientEvents.ExtEvents->Ext.form.Panel event Form.KeyPress But I would need help 1) How do I save pressed keys on client side into a string function form.keypress(sender, key, eOpts) { // what is in here } 2) When enter is pressed how to send that string to server to be processed. Is there any other better solution ? maybe this will help: https://stackoverflow.com/questions/13987300/how-to-capture-enter-key-press <script> function handle(e){ if(e.keyCode === 13){ e.preventDefault(); // Ensure it is only this code that runs alert("Enter was pressed was presses"); } } </script> or function form.keypress(sender, key, eOpts) { if (key==13){ //your action here or ajax event }; } In my practice, I use a barcode reader connected via bluetooth (even mobile terminals with a built-in barcode scanner) and tuniEdit to get the data read by the scanner. I handle the keypress event of this tuniEdit control and take the received data from the server side and work with it. Quote Link to comment Share on other sites More sharing options...
cyracks Posted December 15, 2022 Author Share Posted December 15, 2022 1 hour ago, irigsoft said: function form.keypress(sender, key, eOpts) { if (key==13){ //your action here or ajax event }; } How can keys be saved to a "session" variable, that is sent to the server on key == 13 ? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 15, 2022 Share Posted December 15, 2022 19 minutes ago, cyracks said: How can keys be saved to a "session" variable, that is sent to the server on key == 13 ? @Sherzod can help here , I hope. try this: and I thing You can use function form.keypress(sender, key, eOpts) { if (key==13){ //your action here or ajax event MainForm.uniEdit1.Text := key; }; } Quote Link to comment Share on other sites More sharing options...
cyracks Posted December 15, 2022 Author Share Posted December 15, 2022 10 minutes ago, irigsoft said: try this: Thank you I will try, suggestion solves problem no.2 or how to send data from client to server. (1) create event ExtEvents on client, (2) in client event call ajaxRequest to send data to server, (3) on server catch data in event "Object"AjaxEvent). If the above works, all I need is how to save multiple keypresses to one string/session variable. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 15, 2022 Share Posted December 15, 2022 8 minutes ago, cyracks said: If the above works, all I need is how to save multiple keypresses to one string/session variable. why do you need to save this....., if you catch the last key pressed (enter) in some uniEdit , is it possible to use all previous keys (Edit.text)? I use Edit control and possitioning on edit.Text , read barcode, catch key = Enter and send Edit.Text to server to start search (like example). Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 15, 2022 Share Posted December 15, 2022 16 minutes ago, cyracks said: Thank you I will try, suggestion solves problem no.2 or how to send data from client to server. (1) create event ExtEvents on client, (2) in client event call ajaxRequest to send data to server, (3) on server catch data in event "Object"AjaxEvent). If the above works, all I need is how to save multiple keypresses to one string/session variable. other topic: http://forums.unigui.com/index.php?/topic/12645-do-you-have-to-remove-accentuated-letter-typing-from-the-client-side/#comment-67437 Quote Link to comment Share on other sites More sharing options...
cyracks Posted December 15, 2022 Author Share Posted December 15, 2022 46 minutes ago, irigsoft said: why do you need to save this....., if you catch the last key pressed (enter) in some uniEdit , is it possible to use all previous keys (Edit.text)? Because I want to capture on the application level, otherwise user must always click on the edit before scanning which is not ok. Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted December 16, 2022 Share Posted December 16, 2022 On 12/15/2022 at 1:46 PM, cyracks said: Because I want to capture on the application level Hello Cyracks, Probably you are looking for Hook technics. Try google with these words "delphi hook keyboard scanner". You will find your solution. I will try to find my old program with hook intercepting, without Tedit focused. __________ EDITED: Hummm.....HOOK is ServerSide. Use instead ClientSide on KeyPressed Event as advised by irigsoft. And setFocus to YourEdit on Form.Onactivated Event. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.