Return Key / Enter Key
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Return Key / Enter Key
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
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
-
- Livecode Opensource Backer
- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Re: Return Key / Enter Key
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:
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:
Re: Return Key / Enter Key
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.
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.
-
- Livecode Opensource Backer
- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Re: Return Key / Enter Key
Oh, &*^%$#; that's a real nuisance.0 came up for both key presses - enter & return
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
The easiest thing might be to put this into a closefield handler:
That will strip out extra returns, spaces, tabs, anything that is white space around the entry.
Code: Select all
on closeField
put word 1 to -1 of me into me
end closeField
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Return Key / Enter Key
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.
Try filter without empty on your var or field prior to calculating. This will remove bank (empty) lines.
Andy .... LC CLASSIC ROCKS!
-
- Livecode Opensource Backer
- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Re: Return Key / Enter Key
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.
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
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
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
Andy .... LC CLASSIC ROCKS!
Re: Return Key / Enter Key
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
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
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?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Return Key / Enter Key
Have you been able to test on more than one device?
I've tested on two devices and both work as expeced...
I've tested on two devices and both work as expeced...
Andy .... LC CLASSIC ROCKS!
Re: Return Key / Enter Key
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
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
Last edited by AndyP on Thu Oct 13, 2016 12:34 pm, edited 1 time in total.
Andy .... LC CLASSIC ROCKS!
Re: Return Key / Enter Key
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?
I'm gonna go all through the code again and see if I'm missing anything. and look into filtering...
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]
Re: Return Key / Enter Key
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?
https://www.dropbox.com/s/3hrlayksypgp0 ... ecode?dl=0
Does this work for you using the standard (top) field?
Andy .... LC CLASSIC ROCKS!
Re: Return Key / Enter Key
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?

I will try and implement it on my app and see what happens, how would I bring up the key pad using this method?