I would recommend using the codes listed at
http://www.appgamekit.com/documentation/guides/scancodes.htm to set up a set of constants
#constant KEY_BACK 8
#constant KEY_TAB 9
#constant KEY_ENTER 13
#constant KEY_SHIFT 16
#constant KEY_CONTROL 17
#constant KEY_ESCAPE 27
#constant KEY_SPACE 32
#constant KEY_PAGEUP 33
#constant KEY_PAGEDOWN 34
#constant KEY_END 35
#constant KEY_HOME 36
#constant KEY_LEFT 37
#constant KEY_UP 38
#constant KEY_RIGHT 39
#constant KEY_DOWN 40
#constant KEY_INSERT 45
#constant KEY_DELETE 46
#constant KEY_0 48
...
It makes your code much easier to follow and debug.
if GetRawKeyState( KEY_ESCAPE ) then exit