Page 1 of 1
Return Key / Enter Key
Posted: Tue Oct 11, 2016 12:49 pm
by MarcoPolo
Hi all, I have tried and tried to disable the Retun/Enter key on mobile for Android.
on certain cards I have two fields one for text the other for numbers and each appropriate keyboard pops up as should.
The problem I have is when the user presses the return/enter key it adds an empty line to my lists/variables and as the numbers entered are to be calculated it throws the whole thing out!!!!
the below event handlers have worked on my Desktop app but not in the mobile environment
on returnInField
exit returnInField
end returnInField
on enterInField
exit enterInField
end enterInField
on returnKey
exit returnKey
end returnKey
on enterKey
exit enterKey
end enterKey
any suggestions or workarounds??
Thanks
Mark
Re: Return Key / Enter Key
Posted: Tue Oct 11, 2016 12:51 pm
by richmond62
Personally I'd trap rawKeyDowns.
However, I'm not sure what numbers the Enter and Return keys would return on Android, and as
the Livecode IDE does not run on Android I'm not entirely sure how you'd determine them.
Probably (?) the trick would be to generate an Android standalone to let you know all the rawKey values from this stack:

- RAWK.png (5.93 KiB) Viewed 10741 times
Re: Return Key / Enter Key
Posted: Tue Oct 11, 2016 6:53 pm
by MarcoPolo
Thanks richmond62, a handy tool.
I added a field to my stack with the code behind it at the card level, and 0 came up for both key presses - enter & return.
so tried "0" as the key to no avail???
I'll keep trying.
Re: Return Key / Enter Key
Posted: Tue Oct 11, 2016 7:13 pm
by richmond62
0 came up for both key presses - enter & return
Oh, &*^%$#; that's a real nuisance.
Of course the simple fact might just be that the ENTER and the RETURN key are exactly the same on Android.
This looks ugly:
https://bugs.chromium.org/p/chromium/is ... ?id=118639
In fact, I'm beginning to get a queer feeling about Android:
"It seems there's never a keypress event"
Re: Return Key / Enter Key
Posted: Tue Oct 11, 2016 7:54 pm
by jacque
The easiest thing might be to put this into a closefield handler:
Code: Select all
on closeField
put word 1 to -1 of me into me
end closeField
That will strip out extra returns, spaces, tabs, anything that is white space around the entry.
Re: Return Key / Enter Key
Posted: Tue Oct 11, 2016 9:27 pm
by AndyP
Probably easier to deal with the blank line rather than deal with ...erm..Androids niceties!
Try filter without empty on your var or field prior to calculating. This will remove bank (empty) lines.
Re: Return Key / Enter Key
Posted: Wed Oct 12, 2016 10:01 am
by richmond62
I got my silly Android Nextbook out of the bag where it hangs 99% of the time
and played around with it and had a think about 'Return' and 'Enter' keydowns
and realised how, frankly, stupid, I'd been. One should only expect keyDown
signals on computers that have physical keyboards connected to them: Android
devices [generally] don't have external keyboards connected to them, nor is the
operating system programmed to expect an external keyboard.
As Jacque pointed out . . .
and as Jacque implied but did not overtly state: I missed the point completely, as did someone else.
Re: Return Key / Enter Key
Posted: Wed Oct 12, 2016 12:48 pm
by AndyP
Hi Richmond,
Hmm.however, using your excellent RAWK stack with a field added to allow text input, also gives 65293, as per your image of RAWK. so it looks like this may be a standard response for the Return key. So it should be possible to trap and action against.
This addition to your code, strips return from the focused field in Android
Code: Select all
on rawKeyDown RAWD
put RAWD into fld "rawk"
------------------------
--This addition strips the return as its typed
if RAWD = 65293 then
exit rawKeyDown RAWD
end if
pass rawKeyDown
-------------------------
end rawKeyDown
Re: Return Key / Enter Key
Posted: Wed Oct 12, 2016 8:16 pm
by MarcoPolo
Thanks for the effort guys really appreciated.
I tried the on closeField suggestion from jacque, this was still putting empty lines in my list!! I got the idea though and sure I'm I could work around it, if all else fails.
I tried AndyP's/richmond62 code and this worked for the keyboard but not on the device,
on coming across this page
https://developer.android.com/reference ... Event.html
I changed the code to include this "KEYCODE_ENTER" , "KEYCODE_NUMPAD_ENTER" , "66" & "160".
still no joy

Re: Return Key / Enter Key
Posted: Wed Oct 12, 2016 9:31 pm
by jacque
Right, my method assumes there's only one "real" line and the rest are empty. If there is content in more than one line then it won't work. So it sounds like you allow multi-line entries, only some of which are blank? In that case, the "filter" command is a better choice but we'd need more info on how you're implementing this. Are you using native mobile inputs, or standard LC fields? Can you post the handler that does the filtering?
Re: Return Key / Enter Key
Posted: Thu Oct 13, 2016 5:37 am
by AndyP
Have you been able to test on more than one device?
I've tested on two devices and both work as expeced...
Re: Return Key / Enter Key
Posted: Thu Oct 13, 2016 8:22 am
by AndyP
OK. just done some more testing.
So I think your must be using native fields and the problem is that with a standard field the soft keyboard displays a Return key which can be trapped, but a native field shows a Done key which gives no key code so cannot be trapped!
see this screen video click to view full size..the reduced image is poor
Re: Return Key / Enter Key
Posted: Thu Oct 13, 2016 11:45 am
by MarcoPolo
Ok I'm using standard LC fields, is there a way to turn off multi-line entries? I haven't implemented any filtering as yet, as i'm researching filters.
I have tried it on two devices with the same out come. and I get the enter lcon on the KB not the done tick.
this is the code on the text field should I have any of this code on the card?
Code: Select all
on openfield
set the text of me to empty
if the environment is "mobile" then
mobileSetKeyboardType "default"
end if
end openfield
on closeField
put line 1 of me into me
end closeField
on rawKeyDown RAWD
if RAWD = "65293"or "66" or "160" or "KEYCODE_ENTER" or "KEYCODE_NUMPAD_ENTER" or "Enter key" or "Numeric keypad Enter key" then
exit rawKeyDown RAWD
end if
pass rawKeyDown
end rawKeyDown[/quote]
I'm gonna go all through the code again and see if I'm missing anything. and look into filtering...
Re: Return Key / Enter Key
Posted: Thu Oct 13, 2016 12:18 pm
by AndyP
Here is a link to the stack I am using for testing.
https://www.dropbox.com/s/3hrlayksypgp0 ... ecode?dl=0
Does this work for you using the standard (top) field?
Re: Return Key / Enter Key
Posted: Thu Oct 13, 2016 3:30 pm
by MarcoPolo
Yes Andy this works on my device generating the number 65293 in the content field on pressing the return key
I will try and implement it on my app and see what happens, how would I bring up the key pad using this method?