Stop user pressing Enter in entry field

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
agraham147
Posts: 54
Joined: Thu Apr 19, 2018 6:18 am

Stop user pressing Enter in entry field

Post by agraham147 »

Hi there

I would like to know how to stop the user of my program from pressing the Enter or Return Key for a new line in text entry fields as I only want them to be able to provide 1 line of text. How do I do this please?
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Stop user pressing Enter in entry field

Post by dunbarx »

Hi.

Try this in the field script:

Code: Select all

on returnInfield
end returnInfield

on enterInField
end enterInField
LC will never see messages like "returnInField" that it uses to er, return in a field.

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

Re: Stop user pressing Enter in entry field

Post by jacque »

Alternately, size the height of the field to hold only one line and set the autotab of the field to true in the property inspector.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
agraham147
Posts: 54
Joined: Thu Apr 19, 2018 6:18 am

Re: Stop user pressing Enter in entry field

Post by agraham147 »

Thanks guys :D
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Stop user pressing Enter in entry field

Post by richmond62 »

If that solution is not exciting enough for you, you can try this:

Code: Select all

on rawKeyDown RK
    switch RK
       case 65293
         --do nix
       break
       case 65421
         --do nix
       break
       default
       pass rawKeyDown
     end switch
end rawKeyDown
-
kb.png
-
case 65293 traps the RETURN key (marked in powder blue).

case 65421
traps the ENTER key (marked in pale green).

The reason for this is that to trap BOTH in the way previously suggested you would
have to use

returnInField and

enterInField
.

As the initial question was about stopping people pressing the ENTER key and NOT the RETURN key . . .

Being pedantic is such sweet joy. 8)
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Stop user pressing Enter in entry field

Post by dunbarx »

Richmond.

I was accused, but never convicted of pedantism.

Howeveer, the OP originally did indeed ask to stop both "enter" and "return". 8)

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

Re: Stop user pressing Enter in entry field

Post by richmond62 »

the Enter or Return Key
I am both accused and convicted. :D

HOWEVER: returnInField will ONLY trap the RETURN key.

https://youtu.be/HDMV4UF_-Rs
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Stop user pressing Enter in entry field

Post by dunbarx »

HOWEVER: returnInField will ONLY trap the RETURN key.
Right. As it should. 8)

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

Re: Stop user pressing Enter in entry field

Post by jacque »

Whenever possible I let the engine do it. This functionality is built in and requires no code.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
Post Reply