Page 1 of 1
Stop user pressing Enter in entry field
Posted: Tue Jun 19, 2018 12:42 am
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?
Re: Stop user pressing Enter in entry field
Posted: Tue Jun 19, 2018 2:45 am
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
Re: Stop user pressing Enter in entry field
Posted: Tue Jun 19, 2018 5:57 pm
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.
Re: Stop user pressing Enter in entry field
Posted: Fri Jun 22, 2018 9:02 pm
by agraham147
Thanks guys
Re: Stop user pressing Enter in entry field
Posted: Sat Jun 23, 2018 8:19 am
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
-
-
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.
Re: Stop user pressing Enter in entry field
Posted: Sat Jun 23, 2018 1:52 pm
by dunbarx
Richmond.
I was accused, but never convicted of pedantism.
Howeveer, the OP originally did indeed ask to stop both "enter" and "return".
Craig
Re: Stop user pressing Enter in entry field
Posted: Sat Jun 23, 2018 3:45 pm
by richmond62
the Enter or Return Key
I am both accused and convicted.
HOWEVER:
returnInField will
ONLY trap the
RETURN key.
https://youtu.be/HDMV4UF_-Rs
Re: Stop user pressing Enter in entry field
Posted: Sat Jun 23, 2018 4:54 pm
by dunbarx
HOWEVER: returnInField will ONLY trap the RETURN key.
Right. As it should.
Craig
Re: Stop user pressing Enter in entry field
Posted: Sat Jun 23, 2018 5:36 pm
by jacque
Whenever possible I let the engine do it. This functionality is built in and requires no code.