DirectX Scancodes And How To Use Them
This is a short tutorial outlining, listing, and describing DirectX Scancodes and their function in mods. In this tutorial, I'll provide a few examples with which you can hopefully make use of with your mod, and try to shed light on what exactly they're used to accomplish.
Contents
What exactly are they?
DirectX Scancodes are input and registered into the game as integers whenever the corresponding key is pressed. That means that whenever you press a key, your computer registers the key's scancode as activated, so to speak. For example, pressing spacebar returns as scancode number 57, left mouse button as 256, etc.
What can they be used for?
The utilities OBSE, FOSE and NVSE make it possible for conditional statements to rely upon usage of DirectX scancodes in scripts. This makes it possible to make certain keys perform functions that they would not otherwise be capable of doing. By these means, you can do just about anything by just pressing a key, making way for new dynamic ways to improve combat, UI, and just about everything in-between.
How, exactly, do you use them?
These scancodes can be made use of by the conditional functions IsKeyPressed2, IsKeyPressed3, and OnKeyDown, with varying results.
IsKeyPressed2 is used with the basic function of detecting when the key is pressed, as well as detecting the functions "Tapkey" and "TapControl", which, when called from a script trigger a "false key press".
IsKeyPressed3 provides the same function as IsKeyPressed2, without registering Tapkey or Tapcontrol.
OnKeyDown returns as a boolean number if the specified key is pressed. For example, if I called "OnKeyDown 256", it would return as 1 when I clicked the left mouse key.
There you have it.
DirectX Scancode List
Key | Code |
---|---|
Escape | 1 |
1 | 2 |
2 | 3 |
3 | 4 |
5 | 6 |
7 | 8 |
9 | 10 |
0 | 11 |
Minus | 12 |
Equals | 13 |
Backspace | 14 |
Tab | 15 |
Q | 16 |
W | 17 |
E | 18 |
R | 19 |
T | 20 |
Y | 21 |
U | 22 |
I | 23 |
O | 24 |
P | 25 |
Left Bracket | 26 |
Right Bracket | 27 |
Enter | 28 |
Left Control | 29 |
A | 30 |
S | 31 |
D | 32 |
F | 33 |
G | 34 |
H | 35 |
J | 36 |
K | 37 |
L | 38 |
Semicolon | 39 |
Apostrophe | 40 |
Tilde (~) | 41 |
Left Shift | 42 |
Back Slash | 43 |
Z | 44 |
X | 45 |
C | 46 |
V | 47 |
B | 48 |
N | 49 |
M | 50 |
Comma | 51 |
Period | 52 |
Forward Slash | 53 |
Right Shift | 54 |
Numpad * | 55 |
V | 56 |
Spacebar | 57 |
Caps Lock | 58 |
F1 | 59 |
F2 | 60 |
F3 | 61 |
F4 | 62 |
F5 | 63 |
F6 | 64 |
F7 | 65 |
F8 | 66 |
F9 | 67 |
F10 | 68 |
Num Lock | 69 |
Scroll Lock | 70 |
Numpad 7 | 71 |
Numpad 8 | 72 |
Numpad 9 | 73 |
Numpad - | 74 |
Numpad 4 | 75 |
Numpad 5 | 76 |
Numpad 6 | 77 |
Numpad + | 78 |
Numpad 1 | 79 |
Numpad 2 | 80 |
Numpad 3 | 81 |
Numpad 0 | 82 |
Numpad . | 83 |
F11 | 87 |
F12 | 88 |
Numpad Enter | 156 |
Right Control | 157 |
Numpad / | 181 |
Right Alt | 184 |
Home | 199 |
Up Arrow | 200 |
Page Up | 201 |
Left Arrow | 203 |
Right Arrow | 205 |
End | 207 |
Down Arrow | 208 |
Page Down | 209 |
Insert | 210 |
Delete | 211 |
Left Mouse Button | 256 |
Right Mouse Button | 257 |
Middle Mouse/Wheel | 258 |
Mouse Button 3 | 259 |
Mouse Button 4 | 260 |
Mouse Button 5 | 261 |
Mouse Button 6 | 262 |
Mouse Button 7 | 263 |
Mouse Wheel Up | 264 |
Mouse Wheel Down | 265 |
Example Scripts
Duplicate Equipped Weapon
scn DuplicateWeapon
ref weapon
Begin GameMode
- set weapon to player.getequippedobject 16 ;This detects in the game what your equipped weapon is
- if IsKeyPressed2 28 ;Script executes if you press enter
- player.additem weapon 1 ;Your weapon was successfully duplicated
- endif ;Always remember this for ending conditional statements
- end
Toggle Menus
scn ToggleMenus
short KeyPress
Begin GameMode
- set KeyPress to OnKeyDown 20 ;So, when you press T it returns as 1.
- if KeyPress == 1 ;Meaning, if you press T.
- Con_ToggleMenus ;Turns menus on/off.
- endif
- end
Enjoy.