ON keyDown theKey not working as expected

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

ON keyDown theKey not working as expected

Post by user#606 » Fri Sep 11, 2009 6:14 pm

I had hoped to cause a program to launch when the correct access code was typed in to a field.

global ServerPath,DemoLiveSetting, filenm,VersionTxt,Tposition,CodeNo,Tlength,Tchar,TempText
ON keyDown theKey
IF theKey is a number THEN pass keyDown --works for typing a number only into a field
put 0 into Tposition
put 0 into CodeNo
put the length of field "Addressfield" into Tlength --Field "address" contains a name
repeat for Tlength
put Tposition + 1 into Tposition
put char Tposition of field "Addressfield" into Tchar
put CodeNo + charToNum (Tchar) into CodeNo
end repeat -- this breaks down the name into a sum of ascii characters that form the unlock code
if field "CodeField" contains CodeNo then -- tests to see if the number so far matches the unlock code
launch "\Pt-G\Pt-G Designer version\Windows\Pt-G Designer version.exe" -- this is the program to launce (it does, only if a non-number is typed after the true code)
end if
END keyDown

It works fine if the code number is terminated with a non-digit E.G. 123a
when the correct value is 123.
It will not work for 1234 for example.
Why is this?
Any ideas on how to make this work.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Fri Sep 11, 2009 6:29 pm

since you pass keydown in case of a number you effectively only reach the part of your code after the pass statement if typing a non-number, like a.
if you dont pass the keydown but instead put

Code: Select all

if theKey is a number then put theKey after me
your code should work
regards
Bernd

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Post by user#606 » Fri Sep 11, 2009 6:35 pm

By jingo! That works!

I will mention you in my list of Credits
Thanks so much.

Post Reply