pKey (entering a number)

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
serendippe
Posts: 3
Joined: Sat Nov 28, 2020 2:56 pm

pKey (entering a number)

Post by serendippe » Sat Nov 28, 2020 3:07 pm

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

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: pKey (entering a number)

Post by Klaus » Sat Nov 28, 2020 3:26 pm

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.

serendippe
Posts: 3
Joined: Sat Nov 28, 2020 2:56 pm

Re: pKey (entering a number)

Post by serendippe » Sat Nov 28, 2020 4:04 pm

Thanks a lot,Klaus!

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

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: pKey (entering a number)

Post by Klaus » Sat Nov 28, 2020 4:13 pm

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

serendippe
Posts: 3
Joined: Sat Nov 28, 2020 2:56 pm

Re: pKey (entering a number)

Post by serendippe » Sat Nov 28, 2020 8:52 pm

Many many thanks,Klaus!

Kindest regards!

Luca

Post Reply

Return to “Calculator”