Return Key / Enter Key

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
MarcoPolo
Posts: 12
Joined: Thu Feb 12, 2015 11:34 am

Return Key / Enter Key

Post by MarcoPolo » Tue Oct 11, 2016 12:49 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Return Key / Enter Key

Post by richmond62 » Tue Oct 11, 2016 12:51 pm

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
RAWK.png (5.93 KiB) Viewed 10745 times
RAWK.livecode.zip
stack
(658 Bytes) Downloaded 326 times

MarcoPolo
Posts: 12
Joined: Thu Feb 12, 2015 11:34 am

Re: Return Key / Enter Key

Post by MarcoPolo » Tue Oct 11, 2016 6:53 pm

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.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Return Key / Enter Key

Post by richmond62 » Tue Oct 11, 2016 7:13 pm

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
AndroidKeeze.png
In fact, I'm beginning to get a queer feeling about Android: "It seems there's never a keypress event"

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Return Key / Enter Key

Post by jacque » Tue Oct 11, 2016 7:54 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

AndyP
Posts: 634
Joined: Wed Aug 27, 2008 12:57 pm
Contact:

Re: Return Key / Enter Key

Post by AndyP » Tue Oct 11, 2016 9:27 pm

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.
Andy .... LC CLASSIC ROCKS!

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Return Key / Enter Key

Post by richmond62 » Wed Oct 12, 2016 10:01 am

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.

AndyP
Posts: 634
Joined: Wed Aug 27, 2008 12:57 pm
Contact:

Re: Return Key / Enter Key

Post by AndyP » Wed Oct 12, 2016 12:48 pm

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
Andy .... LC CLASSIC ROCKS!

MarcoPolo
Posts: 12
Joined: Thu Feb 12, 2015 11:34 am

Re: Return Key / Enter Key

Post by MarcoPolo » Wed Oct 12, 2016 8:16 pm

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 :?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Return Key / Enter Key

Post by jacque » Wed Oct 12, 2016 9:31 pm

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

AndyP
Posts: 634
Joined: Wed Aug 27, 2008 12:57 pm
Contact:

Re: Return Key / Enter Key

Post by AndyP » Thu Oct 13, 2016 5:37 am

Have you been able to test on more than one device?

I've tested on two devices and both work as expeced...
Andy .... LC CLASSIC ROCKS!

AndyP
Posts: 634
Joined: Wed Aug 27, 2008 12:57 pm
Contact:

Re: Return Key / Enter Key

Post by AndyP » Thu Oct 13, 2016 8:22 am

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
Attachments
fieldtests1.gif
Last edited by AndyP on Thu Oct 13, 2016 12:34 pm, edited 1 time in total.
Andy .... LC CLASSIC ROCKS!

MarcoPolo
Posts: 12
Joined: Thu Feb 12, 2015 11:34 am

Re: Return Key / Enter Key

Post by MarcoPolo » Thu Oct 13, 2016 11:45 am

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

AndyP
Posts: 634
Joined: Wed Aug 27, 2008 12:57 pm
Contact:

Re: Return Key / Enter Key

Post by AndyP » Thu Oct 13, 2016 12:18 pm

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?
Andy .... LC CLASSIC ROCKS!

MarcoPolo
Posts: 12
Joined: Thu Feb 12, 2015 11:34 am

Re: Return Key / Enter Key

Post by MarcoPolo » Thu Oct 13, 2016 3:30 pm

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?

Post Reply