DirectX Scancodes And How To Use Them

From Nexus Mods Wiki
Revision as of 10:47, 4 January 2011 by Kalizar (talk | contribs) (Created page with "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 hopeful...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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.

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 utility OBSE makes 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

NOTE The list will, for now, be incomplete. When I find time, I will be sure to fill in the scancodes missing from the list.

Key Code
Escape 1
1 2
3 4
5 6
6 7
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
Left Alt 56

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.