For the sake of keeping this to the point, the code contains a list of constants for every key on a standard 101 keyboard, plus an example on how to use it, by making it print out to the screen text descriptions of the modern FPS WASD style controls with capslock to toggle autorun, and ctrl to crouch
`set up our constants
#constant KEY_ESC = 1
#constant KEY_F1 = 59
#constant KEY_F2 = 60
#constant KEY_F3 = 61
#constant KEY_F4 = 62
#constant KEY_F5 = 63
#constant KEY_F6 = 64
#constant KEY_F7 = 65
#constant KEY_F8 = 66
#constant KEY_F9 = 67
#constant KEY_F10 = 68
#constant KEY_F11 = 87
#constant KEY_F12 = 88
#constant KEY_PRTSCR = 183
#constant KEY_SCROLLLOCK = 70
#constant KEY_PAUSE = 197
#constant KEY_TILDE = 41
#constant KEY_1 = 2
#constant KEY_2 = 3
#constant KEY_3 = 4
#constant KEY_4 = 5
#constant KEY_5 = 6
#constant KEY_6 = 7
#constant KEY_7 = 8
#constant KEY_8 = 9
#constant KEY_9 = 10
#constant KEY_0 = 11
#constant KEY_MINUS = 12
#constant KEY_EQUALS = 13
#constant KEY_BACKSPACE = 14
#constant KEY_TAB = 15
#constant KEY_Q = 16
#constant KEY_W = 17
#constant KEY_E = 18
#constant KEY_R = 19
#constant KEY_T = 20
#constant KEY_Y = 21
#constant KEY_U = 22
#constant KEY_I = 23
#constant KEY_O = 24
#constant KEY_P = 25
#constant KEY_LEFTBRACKET = 26
#constant KEY_RIGHTBRACKET = 27
#constant KEY_BACKSLASH = 43
#constant KEY_CAPSLOCK = 58
#constant KEY_A = 30
#constant KEY_S = 31
#constant KEY_D = 32
#constant KEY_F = 33
#constant KEY_G = 34
#constant KEY_H = 35
#constant KEY_J = 36
#constant KEY_K = 37
#constant KEY_L = 38
#constant KEY_SEMICOLON = 39
#constant KEY_APOSTROPHE = 40
#constant KEY_ENTER = 28
#constant KEY_LEFTSHIFT = 42
#constant KEY_Z = 44
#constant KEY_X = 45
#constant KEY_C = 46
#constant KEY_V = 47
#constant KEY_B = 48
#constant KEY_N = 49
#constant KEY_M = 50
#constant KEY_COMMA = 51
#constant KEY_PERIOD = 52
#constant KEY_FRONTSLASH = 53
#constant KEY_RIGHTSHIFT = 54
#constant KEY_LEFTCTRL = 29
#constant KEY_LEFTSYSTEM = 219
#constant KEY_LEFTALT = 56
#constant KEY_SPACE = 57
#constant KEY_RIGHTALT = 184
#constant KEY_RIGHTSYSTEM = 220
#constant KEY_MENU = 221
#constant KEY_RIGHTCTRL = 157
#constant KEY_INSERT = 210
#constant KEY_HOME = 199
#constant KEY_PAGEUP = 201
#constant KEY_DELETE = 211
#constant KEY_END = 207
#constant KEY_PAGEDOWN = 209
#constant KEY_UP = 200
#constant KEY_LEFT = 203
#constant KEY_DOWN = 208
#constant KEY_RIGHT = 205
#constant KEY_NUMLOCK = 69
#constant KEY_PADDIVIDE = 181
#constant KEY_PADMULTIPLY = 55
#constant KEY_PADSUBTRACT = 74
#constant KEY_PADADD = 78
#constant KEY_PADENTER = 156
#constant KEY_PAD1 = 79
#constant KEY_PAD2 = 80
#constant KEY_PAD3 = 81
#constant KEY_PAD4 = 75
#constant KEY_PAD5 = 76
#constant KEY_PAD6 = 77
#constant KEY_PAD7 = 71
#constant KEY_PAD8 = 72
#constant KEY_PAD9 = 73
#constant KEY_PAD0 = 82
#constant KEY_PADDOT = 83
autorun as boolean
dim lastkeys(255)
sync on
do
p$ = ""
if keystate(KEY_CAPSLOCK)
`was capslock not pressed during the last loop?
`if not, then it's safe to toggle
`prevents a function from toggling cosntantly
if lastkeys(KEY_CAPSLOCK) = 0
autorun = autorun xor 1 `"boolean xor 1" is a toggle hack
endif
endif
if keystate(KEY_LEFTSHIFT)
if autorun
p$ = p$ + "Run "
else
p$ = p$ + "Walk "
endif
else
if autorun
p$ = p$ + "Walk "
else
p$ = p$ + "Run "
endif
endif
if keystate(KEY_W)
p$ = p$ + "Forward "
endif
if keystate(KEY_S)
p$ = p$ + "Backward "
endif
if keystate(KEY_A)
p$ = p$ + "StrafeLeft "
endif
if keystate(KEY_D)
p$ = p$ + "StrafeRight "
endif
if keystate(KEY_LEFTCTRL)
p$ = p$ + "Crouching "
endif
cls
set cursor 0,0
print "FPS: " + str$(screen fps())
print p$
`store a list of the last keystates for use with toggle buttons
for i = 1 to 255
lastkeys(i) = keystate(i)
next i
sync
loop
Everything I needed to know about trigonometry, I learned by becoming a game programmer.