Page 1 of 1

pKey (entering a number)

Posted: Sat Nov 28, 2020 3:07 pm
by serendippe
on keyDown pKey

if pKey is a number
then pass keyDown
else beep
end keyDown
i need to insert float number and so on... i tried to write integer or real or float instead number but i get an error...
Can somebody help me?

Kindest regards

Luca

Re: pKey (entering a number)

Posted: Sat Nov 28, 2020 3:26 pm
by Klaus
Hi Luca,

welcome to the forum!

Your script works here, I can only type numbers into the field.
So no idea what your problem is?

Best

Klaus

P.S.
Personal note:
A little "Hello" or something would not have hurt for the very first posting.

Re: pKey (entering a number)

Posted: Sat Nov 28, 2020 4:04 pm
by serendippe
Thanks a lot,Klaus!

But the problem come if i try to insert a decimal number...

Re: pKey (entering a number)

Posted: Sat Nov 28, 2020 4:13 pm
by Klaus
AHA! :D

OK, do this:

Code: Select all

on keyDown pKey 
   ## All numbers are allowed:
   if pKey is a number then
      pass keyDown 
   else
      
      ## Only ONE decimal point allowed, so we have to check:
      if pKey = "." AND "." is not in me then
         pass keydown
      else
         beep
      end if
      beep
   end if
end keyDown
Tested and works!


Best

Klaus

Re: pKey (entering a number)

Posted: Sat Nov 28, 2020 8:52 pm
by serendippe
Many many thanks,Klaus!

Kindest regards!

Luca