User Tools

Site Tools


en:key

Key (Function)

Format

key
key()
key(getUnicode)

returns integer_expression

Description

Immediately returns an integer value corresponding to the currently pressed keyboard key (if the argument is omitted or false), returns the Unicode character number if the argument is true. If no key has been pressed since the last call to the key function then the number zero (0) will be returned.

In Unicoide mode the key function will not return keypresses like backspace, escape, arrows, shift, alt, or the control keys. It will return upper/lowercase letters.

Note

if key = 47 then print key

will not display the desired results, because it's calling key twice in succession, and will return different values each time. This code will do what you want:

a = key
if a = 47 then print a

Partial List of Keys

ESC=16777216Space=32
0=481=492=503=514=525=536=547=55
8=569=57
A=65B=66C=67D=68E=69F=70G=71H=72
I=73J=74K=75L=76M=77N=78O=79P=80
Q=81R=82S=83T=84U=85V=86W=87X=88
Y=89Z=90
Down Arrow=16777237Up Arrow=16777235Left Arrow=16777234Right Arrow=16777236

Click here for a complete list of key values

Example

#press any keys
loop:
pause 1
a = key
print a+"  "+chr(a)
goto loop

Example

# get unicode letters until you press a control x
while true
	k = key(true)
	if k <> 0 then
		print k, chr(k)
		if k = 24 then exit while
	endif
	pause .1
end while

See Also

History

2.0.0.11added optional Unicode character argument
en/key.txt · Last modified: 2020/06/29 17:41 by admin