Format:
LONG REF->xKeyPressed LONG_code
Monitors the status of the keyboard (and mouse buttons). This can be similar to GetPCSneaking, but actually detects whether a particular key is really being pressed. If input parameter code is a Virtual Key Code (between 1 and 254) the return value will indicate the status of that key and a non-zero value means the key is being pressed. If the input code is 0, then on each call, the function will return the key code for the key (or one of the keys) currently being pressed. The specific values for the virtual key codes can be found at the bottom of this page[[http://msdn.microsoft.com/|]]. Some of the codes match different keys on different keyboard layouts. The purpose of REF is unknown currently. Does not accept global variables.

Examples:

  • Detecting a specific key:
short keyRET
setx keyRET to xKeyPressed, 13 ;the ENTER key
if ( keyRET ) ;use ifx if you want to use any enhanced functions within the if statement
;do appopriate actions
endif

  • Detecting any key that the user chooses
short temp_key
setx temp_key to xKeyPressed, 0

  • (Advanced) Dislpay a dialogue to get the players preference for a specific key (for example for mod configuration purposes)
short temp_key
short controlvar
short button

if (controlvar == 5)
set button to getbuttonpressed
if (button == -1)
return
endif
if (scriptrunning rvr_dec_main_script == 0)
startscript rvr_dec_main_script
endif
set temp_key to 0
set controlvar to 0
set button to 0
stopscript rvr_dec_config
return
endif

if (controlvar == 0) ;this is the first action the script will take
messagebox "Please choose a key. Clicking OK will have no effect until you do so." "OK"
set controlvar to 1 ;do this once when called
return
endif

if ( MenuMode == 0) ;if the messagebox is gone
if (temp_key <= 1) ;value returned 1 = mouse button used to click the ok button :)
set controlvar to 0 ;display the message again
set temp_key to 0 ;reset key value
return
endif
endif

if (tmp_key <=1 ) ;this is to prevent unwanted keys from being chosen,
;in this case mouse button is not registered as valid, you can add more key values here
;for example if you don't want the user to choose ESC (which would be very sensible in almost any
;situation), replace '1' with '27'
set temp_key to 0
endif

if (menumode == 0)
if (controlvar != 0)
set controlvar to 0
return
endif
endif

ifx (temp_key)
; MenuTest 0
messagebox "Please remember the key you selected, if you forget it or want to change your preference, type 'startscript rvr_dec_config' sans the quotes in the console. Or simply delete the file rvr_decorator in your 'Data files/MWSE' folder. Happy decorating!", "OK."
xFileRewind "rvr_decorator"
xFileWriteShort "rvr_decorator" temp_key
; messagebox "the chosen button's virtual code is %g" temp_key
set rvr_key to temp_key
set controlvar to 5
endif

setx temp_key to xKeyPressed, 0

setx keyCTRL to xKeyPressed, 17
setx keyR to xKeyPressed, 39
if ( keyR )
if ( keyCTRL )
;do appopriate actions for ctrl+arrow right
endif
if ( timer_keyR <= 0.350 )
set timer_keyR to timer_keyR + getsecondspassed ;
elseif ( incr_keyR <= 15 )
set incr_keyR to incr_keyR + 2
set timer_keyR to 0.1
else
set incr_keyR to 15
endif
set currxangle to (currxangle + incr_keyR)
if (currxangle >= 360)
set currxangle to (currxangle - 360)
endif
SetAngle, x, currxangle
else
set incr_keyR to 1
set timer_keyR to 0
endif

Symbolic constant name
Value (hex)
Value (dec)
Mouse or keyboard equivalents

Symbolic constant name
Value (hex)
Value (dec)
Mouse or keyboard equivalents
VK_LBUTTON
1
1
Left mouse button

VK_F4
73
115
F4 key
VK_RBUTTON
2
2
Right mouse button

VK_F5
74
116
F5 key
VK_CANCEL
3
3
Control-break processing

VK_F6
75
117
F6 key
VK_MBUTTON
4
4
Middle mouse button (three-button mouse)

VK_F7
76
118
F7 key
VK_XBUTTON1
5
5
Windows 2000/XP: X1 mouse button

VK_F8
77
119
F8 key
VK_XBUTTON2
6
6
Windows 2000/XP: X2 mouse button

VK_F9
78
120
F9 key
-
7
7
Undefined

VK_F10
79
121
F10 key
VK_BACK
8
8
BACKSPACE key

VK_F11
7A
122
F11 key
VK_TAB
9
9
TAB key

VK_F12
7B
123
F12 key
-
0A-0B
10-11
Reserved

VK_F13
7C
124
F13 key
VK_CLEAR
0C
12
CLEAR key

VK_F14
7D
125
F14 key
VK_RETURN
0D
13
ENTER key

VK_F15
7E
126
F15 key
-
0E-0F
14-15
Undefined

VK_F16
7F
127
F16 key
VK_SHIFT
10
16
SHIFT key

VK_F17
80
128
F17 key
VK_CONTROL
11
17
CTRL key

VK_F18
81
129
F18 key
VK_MENU
12
18
ALT key

VK_F19
82
130
F19 key
VK_PAUSE
13
19
PAUSE key

VK_F20
83
131
F20 key
VK_CAPITAL
14
20
CAPS LOCK key

VK_F21
84
132
F21 key
VK_KANA
15
21
IME Kana mode

VK_F22
85
133
F22 key
VK_HANGUEL
15
21
IME Hanguel mode (maintained for compatibility; use VK_HANGUL)

VK_F23
86
134
F23 key
VK_HANGUL
15
21
IME Hangul mode

VK_F24
87
135
F24 key
-
16
22
Undefined

-
88-8F
136-143
Unassigned
VK_JUNJA
17
23
IME Junja mode

VK_NUMLOCK
90
144
NUM LOCK key
VK_FINAL
18
24
IME final mode

VK_SCROLL
91
145
SCROLL LOCK key
VK_HANJA
19
25
IME Hanja mode

VK_OEM_NEC_EQUAL
92
146
NEC PC-9800 kbd definitions: '=' key on numpad
VK_KANJI
19
25
IME Kanji mode

VK_OEM_FJ_JISHO
92
146
Fujitsu/OASYS kbd definitions: 'Dictionary' key
-
1A
26
Undefined

VK_OEM_FJ_MASSHOU
93
147
Fujitsu/OASYS kbd definitions: 'Unregister word' key
VK_ESCAPE
1B
27
ESC key

VK_OEM_FJ_TOUROKU
94
148
Fujitsu/OASYS kbd definitions: 'Register word' key
VK_CONVERT
1C
28
IME convert (Reserved for Kanji systems)

VK_OEM_FJ_LOYA
95
149
Fujitsu/OASYS kbd definitions: 'Left OYAYUBI' key
VK_NONCONVERT
1D
29
IME nonconvert (Reserved for Kanji systems)

VK_OEM_FJ_ROYA
96
150
Fujitsu/OASYS kbd definitions: 'Right OYAYUBI' key
VK_ACCEPT
1E
30
IME accept (Reserved for Kanji systems)

-
97-9F
151-159
Unassigned
VK_MODECHANGE
1F
31
IME mode change request (Reserved for Kanji systems)

VK_LSHIFT
A0
160
Left SHIFT key
VK_SPACE
20
32
SPACEBAR

VK_RSHIFT
A1
161
Right SHIFT key
VK_PRIOR
21
33
PAGE UP key

VK_LCONTROL
A2
162
Left CONTROL key
VK_NEXT
22
34
PAGE DOWN key

VK_RCONTROL
A3
163
Right CONTROL key
VK_END
23
35
END key

VK_LMENU
A4
164
Left MENU key
VK_HOME
24
36
HOME key

VK_RMENU
A5
165
Right MENU key
VK_LEFT
25
37
LEFT ARROW key

VK_BROWSER_BACK
A6
166
Windows 2000/XP: Browser Back key
VK_UP
26
38
UP ARROW key

VK_BROWSER_FORWARD
A7
167
Windows 2000/XP: Browser Forward key
VK_RIGHT
27
39
RIGHT ARROW key

VK_BROWSER_REFRESH
A8
168
Windows 2000/XP: Browser Refresh key
VK_DOWN
28
40
DOWN ARROW key

VK_BROWSER_STOP
A9
169
Windows 2000/XP: Browser Stop key
VK_SELECT
29
41
SELECT key

VK_BROWSER_SEARCH
AA
170
Windows 2000/XP: Browser Search key
VK_PRINT
2A
42
PRINT key

VK_BROWSER_FAVORITES
AB
171
Windows 2000/XP: Browser Favorites key
VK_EXECUTE
2B
43
EXECUTE key

VK_BROWSER_HOME
AC
172
Windows 2000/XP: Browser Start and Home key
VK_SNAPSHOT
2C
44
PRINT SCREEN key for Windows 3.0 and later

VK_VOLUME_MUTE
AD
173
Windows 2000/XP: Volume Mute key
VK_INSERT
2D
45
INS key

VK_VOLUME_DOWN
AE
174
Windows 2000/XP: Volume Down key
VK_DELETE
2E
46
DEL key

VK_VOLUME_UP
AF
175
Windows 2000/XP: Volume Up key
VK_HELP
2F
47
HELP key

VK_MEDIA_NEXT_TRACK
B0
176
Windows 2000/XP: Next Track key
VK_0
30
48
0 key

VK_MEDIA_PREV_TRACK
B1
177
Windows 2000/XP: Previous Track key
VK_1
31
49
1 key

VK_MEDIA_STOP
B2
178
Windows 2000/XP: Stop Media key
VK_2
32
50
2 key

VK_MEDIA_PLAY_PAUSE
B3
179
Windows 2000/XP: Play/Pause Media key
VK_3
33
51
3 key

VK_LAUNCH_MAIL
B4
180
Windows 2000/XP: Start Mail key
VK_4
34
52
4 key

VK_LAUNCH_MEDIA_SELECT
B5
181
Windows 2000/XP: Select Media key
VK_5
35
53
5 key

VK_LAUNCH_APP1
B6
182
Windows 2000/XP: Start Application 1 key
VK_6
36
54
6 key

VK_LAUNCH_APP2
B7
183
Windows 2000/XP: Start Application 2 key
VK_7
37
55
7 key

-
B8-B9
184-185
Reserved
VK_8
38
56
8 key

VK_OEM_1
BA
186
Windows 2000/XP: For the US standard keyboard, the ';:' key
VK_9
39
57
9 key

VK_OEM_PLUS
BB
187
Windows 2000/XP: For any country/region, the '+' key
-
3A-40
58-64
Undefined

VK_OEM_COMMA
BC
188
Windows 2000/XP: For any country/region, the ',' key
VK_A
41
65
A key

VK_OEM_MINUS
BD
189
Windows 2000/XP: For any country/region, the '-' key
VK_B
42
66
B key

VK_OEM_PERIOD
BE
190
Windows 2000/XP: For any country/region, the '.' key
VK_C
43
67
C key

VK_OEM_2
BF
191
Windows 2000/XP: For the US standard keyboard, the '/?' key
VK_D
44
68
D key

VK_OEM_3
C0
192
Windows 2000/XP: For the US standard keyboard, the '`~' key
VK_E
45
69
E key

-
C1-D7
193-215
Reserved
VK_F
46
70
F key

-
D8-DA
216-218
Unassigned
VK_G
47
71
G key

VK_OEM_4
DB
219
Windows 2000/XP: For the US standard keyboard, the '[{' key
VK_H
48
72
H key

VK_OEM_5
DC
220
Windows 2000/XP: For the US standard keyboard, the '\|' key
VK_I
49
73
I key

VK_OEM_6
DD
221
Windows 2000/XP: For the US standard keyboard, the ']}' key
VK_J
4A
74
J key

VK_OEM_7
DE
222
Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key
VK_K
4B
75
K key

VK_OEM_8
DF
223

VK_L
4C
76
L key

-
E0
224
Reserved
VK_M
4D
77
M key


E1
225
OEM specific
VK_N
4E
78
N key

VK_OEM_102
E2
226
Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard
VK_O
4F
79
O key

-
E3-E4
227-228
OEM specific
VK_P
50
80
P key

VK_PROCESSKEY
E5
229
Windows 95/98, Windows NT 4.0, Windows 2000/XP: IME PROCESS key
VK_Q
51
81
Q key

-
E6
230
OEM specific
VK_R
52
82
R key

VK_PACKET
E7
231
Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT , SendInput , WM_KEYDOWN , and WM_KEYUP
VK_S
53
83
S key

-
E8
232
Unassigned
VK_T
54
84
T key

VK_OEM_RESET
E9
233
Only used by Nokia.
VK_U
55
85
U key

VK_OEM_JUMP
EA
234
Only used by Nokia.
VK_V
56
86
V key

VK_OEM_PA1
EB
235
Only used by Nokia.
VK_W
57
87
W key

VK_OEM_PA2
EC
236
Only used by Nokia.
VK_X
58
88
X key

VK_OEM_PA3
ED
237
Only used by Nokia.
VK_Y
59
89
Y key

VK_OEM_WSCTRL
EE
238
Only used by Nokia.
VK_Z
5A
90
Z key

VK_OEM_CUSEL
EF
239
Only used by Nokia.
VK_LWIN
5B
91
Left Windows key (Microsoft Natural Keyboard)

VK_OEM_ATTN
F0
240
Only used by Nokia.
VK_RWIN
5C
92
Right Windows key (Microsoft Natural Keyboard)

VK_OEM_FINNISH
F1
241
Only used by Nokia.
VK_APPS
5D
93
Applications key (Microsoft Natural Keyboard)

VK_OEM_COPY
F2
242
Only used by Nokia.
-
5E
94
Reserved

VK_OEM_AUTO
F3
243
Only used by Nokia.
VK_SLEEP
5F
95
Computer Sleep key

VK_OEM_ENLW
F4
244
Only used by Nokia.
VK_NUMPAD0
60
96
Numeric keypad 0 key

VK_OEM_BACKTAB
F5
245
Only used by Nokia.
VK_NUMPAD1
61
97
Numeric keypad 1 key

VK_ATTN
F6
246
Attn key
VK_NUMPAD2
62
98
Numeric keypad 2 key

VK_CRSEL
F7
247
CrSel key
VK_NUMPAD3
63
99
Numeric keypad 3 key

VK_EXSEL
F8
248
ExSel key
VK_NUMPAD4
64
100
Numeric keypad 4 key

VK_EREOF
F9
249
Erase EOF key
VK_NUMPAD5
65
101
Numeric keypad 5 key

VK_PLAY
FA
250
Play key
VK_NUMPAD6
66
102
Numeric keypad 6 key

VK_ZOOM
FB
251
Zoom key
VK_NUMPAD7
67
103
Numeric keypad 7 key

VK_NONAME
FC
252
Reserved for future use.
VK_NUMPAD8
68
104
Numeric keypad 8 key

VK_PA1
FD
253
PA1 key
VK_NUMPAD9
69
105
Numeric keypad 9 key

VK_OEM_CLEAR
FE
254
Clear key