ASK Command Return Button means "OK"

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Manu9351
Posts: 19
Joined: Sun Jan 07, 2018 8:48 pm

ASK Command Return Button means "OK"

Post by Manu9351 » Sun Jan 14, 2018 6:51 pm

is there any possibility to press the OK button at an ASK-Event with the ENTER Button on a mobile device?
My situation is: I have an Bluetooth-Barcode-Reader, so the App asks with an Ask-command for a barcode.
EAN screenshot.jpg
I scan a barcode with the bluetooth device, and the device inserts a "RETURN" after the line of numbers automatically. But i want that the "RETURN" means "PRESS OK" and not "Go to line 2" like i press Enter in a word document.
Anyone have an idea what i mean?

THANK YOU!!

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: ASK Command Return Button means "OK"

Post by quailcreek » Sun Jan 14, 2018 8:50 pm

I think I understand what you are asking. Maybe post that part of your code that is setting the return char.
Tom
MacBook Pro OS Mojave 10.14

Manu9351
Posts: 19
Joined: Sun Jan 07, 2018 8:48 pm

Re: ASK Command Return Button means "OK"

Post by Manu9351 » Sun Jan 14, 2018 9:05 pm

quailcreek wrote:
Sun Jan 14, 2018 8:50 pm
I think I understand what you are asking. Maybe post that part of your code that is setting the return char.
That's just this, where i have to set the return code?

Code: Select all

global EANTemp
on mouseUp
   ask "Bitte scannen Sie den EAN Code!" //English: Please scan the barcode
   put it into EANTemp
   put it into field "field_EAN"
end mouseUp

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: ASK Command Return Button means "OK"

Post by quailcreek » Sun Jan 14, 2018 9:26 pm

I've written a couple of scanner apps so I understand that it puts a RETURN char at the end. This is how I handle it.

Code: Select all

 if the last char of EANTemp is RETURN then delete the last char of EANTemp
Tom
MacBook Pro OS Mojave 10.14

Manu9351
Posts: 19
Joined: Sun Jan 07, 2018 8:48 pm

Re: ASK Command Return Button means "OK"

Post by Manu9351 » Sun Jan 14, 2018 9:41 pm

quailcreek wrote:
Sun Jan 14, 2018 9:26 pm
I've written a couple of scanner apps so I understand that it puts a RETURN char at the end. This is how I handle it.

Code: Select all

 if the last char of EANTemp is RETURN then delete the last char of EANTemp
The return is not thw problem, its possible to turn this last return in the properties from the scanner off.

But i want the the app understands instead of the return "press OK Button"

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: ASK Command Return Button means "OK"

Post by quailcreek » Sun Jan 14, 2018 9:57 pm

Ok, so you want the return char to end the ask interaction without letting the user examine the scan data. I see. I'm not sure how to do that.
Tom
MacBook Pro OS Mojave 10.14

Manu9351
Posts: 19
Joined: Sun Jan 07, 2018 8:48 pm

Re: ASK Command Return Button means "OK"

Post by Manu9351 » Sun Jan 14, 2018 10:17 pm

quailcreek wrote:
Sun Jan 14, 2018 9:57 pm
Ok, so you want the return char to end the ask interaction without letting the user examine the scan data. I see. I'm not sure how to do that.
correct, that's what i want. The scan data MUST be right, because the barcode scanner enters the line of numbers. No need to examine it before return

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: ASK Command Return Button means "OK"

Post by jacque » Mon Jan 15, 2018 9:15 pm

I haven't tried it, but an Answer dialog may work since it doesn't have an editable field.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: ASK Command Return Button means "OK"

Post by Newbie4 » Mon Jan 15, 2018 9:48 pm

Instead of a button, just put this code into the script of the field "field_EAN":

Code: Select all

on returnInField
   (put your code to process the number here)
end returnInField
and

Code: Select all

on enterInField
   (put your code to process the number here)
end enterInField
it will handle the number when it receives the "return" or "Enter" code from the scanner
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: ASK Command Return Button means "OK"

Post by jacque » Tue Jan 16, 2018 12:15 am

From the looks of it, the script is using the built-in Ask dialog on Android, which isn't editable.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: ASK Command Return Button means "OK"

Post by Newbie4 » Tue Jan 16, 2018 12:32 am

But the ask is in the button. I assume that the user presses a button to select if they are using a scanner or entering the number by hand. My point is that he does not need the buttons to choose. All he needs is a field with that code in it. It will handle a number entered manually or using a scanner.

If he can not remove the "Ask", he can program his scanner to work with the button.
Most scanners have a way to program them for different types of barcodes (code 39, 128, UPC, etc) They also come with a way to include/exclude a return with the number. If the scanner is not programmable, there is usually scan codes to set them up. If he has the scanner add 2 returns after the number, the button will work.
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: ASK Command Return Button means "OK"

Post by AxWald » Tue Jan 16, 2018 4:51 pm

Hi,

I can see the problem - the signal from the scanner is coming as keyboard input, and has to be caught somewhere. But as soon as you focus on any field (on mobile), this nasty keyboard pops up, covering half the screen.

This way, opening an ask dialogue is a good way to fetch it. Only now the user sees some strange data coming in, and has a great opportunity to manipulate it, and mess the things up. So it would be fine if the incoming data itself would "hit the OK button", but I assume there's no way to do it.

Would I have to do this, I'd try the following approach:

To scan, the user has to press a "EAN scannen" button:

Code: Select all

global gScanData
on mouseUp
   put empty into gScanData
   go card "ScanPage" of this stack
end mouseUp
Card "ScanPage" only has the prompt "Bitte jetzt scannen!" ("Scan now!"), a "Cancel/ Abbrechen" button, and 2 handlers in the card script:

Code: Select all

global gScanData
on keydown what
   put what after gScanData
end keydown

on returnkey
   go cd 1 of this stack  --  or where ever ...
   ScanDone
end returnkey
Card 1 now has the last handler:

Code: Select all

global gScanData
on ScanDone
   put gScanData  --  or do something useful with it ;-)
end ScanDone
Caution: Keydown only reports chars and numbers, so if the scanner sends control chars this doesn't work. Use RawKeyDown in this case.
And - this isn't tested, it's just an idea. So it may not work at all ...

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Manu9351
Posts: 19
Joined: Sun Jan 07, 2018 8:48 pm

Re: ASK Command Return Button means "OK"

Post by Manu9351 » Tue Jan 16, 2018 5:16 pm

Newbie4 wrote:
Tue Jan 16, 2018 12:32 am
But the ask is in the button. I assume that the user presses a button to select if they are using a scanner or entering the number by hand. My point is that he does not need the buttons to choose. All he needs is a field with that code in it. It will handle a number entered manually or using a scanner.

If he can not remove the "Ask", he can program his scanner to work with the button.
Most scanners have a way to program them for different types of barcodes (code 39, 128, UPC, etc) They also come with a way to include/exclude a return with the number. If the scanner is not programmable, there is usually scan codes to set them up. If he has the scanner add 2 returns after the number, the button will work.
i've tried to use just the field below with the code of the button, i can write the code manually, that's no problem. But when i scan it with the barcode reader, no line of number appears in the field.. so the button was my compromise solution. But i'll try it again tomorrow with the code from you.

& yes, my scanner is programmable to include/exclude a return after the numbers. But the return after the numbers causes a jump into the 2nd line, but no "return" like an OK.

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: ASK Command Return Button means "OK"

Post by Newbie4 » Tue Jan 16, 2018 6:47 pm

Are you using a "software" scanner or a hardware scanner with your Android phone?

I tested both solutions and they work on a computer. My scanner does not connect/input into my cellphone so I could not fully test it under Android. You might have to set the focus to the field and turn off the keyboard. The code works, so it must be a problem with the scanner or the Android platform.
You might have to experiment some more or post a question on the Android forum. Maybe someone can help you there.

These are the two methods that worked for me:

1. With the button method and using the Ask command, you have to program the scanner to include 2 "returns" after the number. One to end the input and the second one for the "Ok" button of the dialog.

You can leave the code as it is

Code: Select all

global EANTemp
on mouseUp
   ask "Bitte scannen Sie den EAN Code!" //English: Please scan the barcode
   put it into EANTemp
   put it into field "field_EAN"
end mouseUp
2. With the field method you have to add the "returnInField" and "enterInField" scripts to the field to limit the input to one line (the number) and return control to your program. You only need to program the scanner to include only 1 "return" after the number. You do not need any buttons for this method and it also enables you to manually input the numbers.

remove the button and just use the field

in the script for the field "field_EAN" add this:

Code: Select all

on returnInField
   (put your code to process the number here)
end returnInField
on enterInField
   (put your code to process the number here)
end enterInField

Make sure that your scanner is working with a simple test field. If you do not see any numbers, then try setting the focus to that field and see if that makes a difference.
Good luck and come back with what happens.
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

Post Reply

Return to “Talking LiveCode”