Page 1 of 1

Setting focus on the field in pre for a barcode scan

Posted: Wed Mar 23, 2016 10:53 pm
by quailcreek
Hi,
For this application I’m not generating the barcode so they’re being read right from the product packaging. The scanner I have to work with puts a CR after the last char of the barcode so I’m using rawKeyDown to capture that. Is that typical of all BC readers to add the CR in this situation?

I have a preOpenCard script that set the focus on a fld for the initial scan. If the fld has focus before the scan, all the chars of the barcode are read into the fld. The problem I’m having is that if the fld does not already have focus naturally it needs to be set. With the code below it sets the focus but the first char of the barcode is missing. This also happens if I just type from the keyboard without the fld having focus. Is there a better way to set the focus on the fld before the keyDown or rawKeyDown?

This is in the card script. If you put this into the card script and have a fld named barcode on the cd. Then, with the fld not having focus, type a key on the keyboard. Then type a second key.

Code: Select all

on KeyDown
   if fld "Barcode" is not the focusedObject then
      focus on fld "Barcode"
      pass KeyDown
   end if
   pass KeyDown
end KeyDown

on rawKeyDown theKey
   if theKey is 65293 OR  theKey is 65421 then
      delete last char of fld "Barcode"
      put fld "Barcode" into sBarcode
      manageBarcode
      put empty into fld "Barcode"
      
   else
      pass rawKeyDown
   end if
end rawKeyDown

Re: Setting focus on the field in preo for a barcode sacn

Posted: Thu Mar 24, 2016 4:11 pm
by jacque
Try this:

Code: Select all

on KeyDown pKey
   if fld "Barcode" is not the focusedObject then
      focus on fld "Barcode" 
      put pKey after fld "barcode"
   else
      pass KeyDown
   end if
end KeyDown

Re: Setting focus on the field in preo for a barcode sacn

Posted: Thu Mar 24, 2016 5:06 pm
by quailcreek
Thank you, Jacqueline. That got me what I needed.

Re: Setting focus on the field in pre for a barcode scan

Posted: Thu Mar 24, 2016 7:37 pm
by quailcreek
As a follow up.

This will return true or false:

Code: Select all

if the short name of focusedObject() is not "Barcode" then
This will always return true even if the fld has focus:

Code: Select all

if fld "Barcode" is not the focusedObject then
Second question:
Is there a way to determine which keyboard the input is coming from? Is there a keyboard ID or does a scanner have a different keyboard type? I'd like to be able to determine where the keyDown is coming from.