Jump to content

Barcode Scanner


cyracks

Recommended Posts

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 ?

Link to comment
Share on other sites

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.
 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
  };

}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...