Restrict certain keyboard keys

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
davidmills
Posts: 16
Joined: Tue Jan 13, 2015 1:21 am

Restrict certain keyboard keys

Post by davidmills » Fri Apr 03, 2015 9:21 am

On my Android why does only the on returnInField work and yet none of the others do?
Thanks
Dave

Code: Select all

on openField
mobileSetKeyboardType "numeric"
end openField

on returnInField
   beep
   exit to top
end returnInField

on commaInField
   beep
   exit to top
end commaInField

on spaceInField
   beep
   exit to top
end spaceInField

end keyDown

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Restrict certain keyboard keys

Post by jmburnod » Fri Apr 03, 2015 9:59 am

Hi Dave,

You can use keyup to do that

Code: Select all

on keyup pKey
   if pKey is in "abc" then
      beep
   else
      put pKey
   end if
end keyup
Have also a look to keydown, rawkeydown, rawkeyUp
Best regards
Jean-Marc
https://alternatic.ch

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Restrict certain keyboard keys

Post by SparkOut » Fri Apr 03, 2015 11:56 am

Just to elaborate, the engine sends different messages when things happen. One of the engine messages is enterInField which is sent when the enter key is pressed in the field. There is no such message for comma, or most alphanumeric keys. So you need to use the more generalised messages as Jean-Marc says.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Restrict certain keyboard keys

Post by Klaus » Fri Apr 03, 2015 12:44 pm

Hi Dave,
davidmills wrote:On my Android why does only the on returnInField work and yet none of the others do?
the answer is quite simple: If it is not listed in the DICTIONARY (hint, hint!), then it is not build-in! 8)


Best

Klaus

davidmills
Posts: 16
Joined: Tue Jan 13, 2015 1:21 am

Re: Restrict certain keyboard keys

Post by davidmills » Fri Apr 03, 2015 1:25 pm

Thanks for all your replies. But I don't understand from the example what I'm supposed to replace my present script with, other than I presume the "abc" is the field name.
Thanks
Dave

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Restrict certain keyboard keys

Post by jmburnod » Fri Apr 03, 2015 2:01 pm

Hi Dave
"abc" is the field name.
No that is a list of chars you want avoïd.
https://alternatic.ch

davidmills
Posts: 16
Joined: Tue Jan 13, 2015 1:21 am

Re: Restrict certain keyboard keys

Post by davidmills » Fri Apr 03, 2015 4:22 pm

Thanks and whilst is now working OK. Is there a way to remove the incorrect characters whilst still in the field other than doing a manual delete?
Dave

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Restrict certain keyboard keys

Post by Thierry » Fri Apr 03, 2015 4:51 pm

davidmills wrote:Thanks and whilst is now working OK. Is there a way to remove the incorrect characters whilst still in the field other than doing a manual delete?
Dave
What about this:

Considering you don't want a, b and c characters:

Code: Select all

put replaceText( theText, "[abc]", empty)
Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

davidmills
Posts: 16
Joined: Tue Jan 13, 2015 1:21 am

Re: Restrict certain keyboard keys

Post by davidmills » Fri Apr 03, 2015 8:34 pm

Thank you Thierry. It's the comma and space I don't want, but where do I add your script line as I tried line 13 after beep?
Dave

Code: Select all

on openField
mobileSetKeyboardType "numeric"
end openField

on returnInField
   beep
   exit to top
end returnInField

on keyup pKey
   if pKey is in ", " then
   beep
   else
   put pKey
end if
end keyup

Post Reply