User Tools

Site Tools


en:key

Key (Function)

Format

key
key()

returns integer_expression

Description

Immediately returns an integer value corresponding to the currently pressed keyboard key. If no key has been pressed since the last call to the key function then the number zero (0) will be returned. This function returns the code for the key pressed not always the ASCII value of the character.

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

See Also

en/key.txt · Last modified: 2016/08/12 11:51 by admin