User:Azeon/Lua Inputs

From SRB2 Wiki
Jump to navigation Jump to search

Global variables

Name Variable type Description
mouse mouse_t The primary player's mouse.
mouse2 mouse_t The secondary player's mouse.

Hooks

KeyDown

Hook format: addHook("KeyDown", functionname)

Function format: function(keyevent_t keyevent)

Function return value: Boolean (override default behavior?)

Executes when the key specified by the key number keynum is pressed outside of a menu or the console. If the function returns true, the default behavior is overridden; otherwise, it will be performed after executing the function.

KeyUp

Hook format: addHook("KeyUp", functionname)

Function format: function(keyevent_t keyevent)

Function return value: Boolean (override default behavior?)

Executes when the key specified by the key number keynum is released outside of a menu or the console. If the function returns true, the default behavior is overridden; otherwise, it will be performed after executing the function.

Tables

Name Array type Usage # (Length) Description
gamekeydown boolean gamekeydown[keynum] #gamekeydown
→ Number of keys
This table is used to look up or modify the pressed state for a specific key.

Userdata structures

mouse_t

General
Accessibility Read-only
Allows custom variables No
# (Length) Mouse number
mouse_t structure
Name Type Accessibility Description/Misc notes
dx INT32 Read-only The change in position along the x-axis.
dy INT32 Read-only The change in position along the y-axis.
mlookdy INT32 Read-only The change in position along the y-axis for use in mouse-looking.
rdx INT32 Read-only The real change in position along the x-axis unadjusted for sensitivity settings.
rdy INT32 Read-only The real change in position along the y-axis unadjusted for sensitivity settings.
buttons UINT16 Read-only Contains flags representing buttons currently pressed (MB_* constants should be used).

keyevent_t

General
Accessibility Read-only
Allows custom variables No
# (Length) nil
keyevent_t structure
Name Type Accessibility Description/Misc notes
name string Read-only The name of the key that fired this event. Equivalent to input.keyNumToName(keyevent.num).
num INT32 Read-only The number of the key that fired this event.
repeated boolean Read-only Whether this event was fired due to a repeat event. (For the KeyUp hook, this is always false.)

Functions

Function Return value(s) Description
input.gameControlDown(int gc) boolean Returns whether the game control gc (a gc_* constant) is currently pressed for the primary player.
input.gameControl2Down(int gc) boolean Returns whether the game control gc (a gc_* constant) is currently pressed for the secondary player.
input.gameControlToKeyNum(int gc) int,int Returns the numbers of the keys bound to the game control gc (a gc_* constant) for the primary player.
input.gameControl2ToKeyNum(int gc) int,int Returns the numbers of the keys bound to the game control gc (a gc_* constant) for the secondary player.
input.joyAxis(int axissel) int Returns the primary player's joystick's position on the axis specified by axissel (a JA_* constant).
input.joy2Axis(int axissel) int Returns the secondary player's joystick's position on the axis specified by axissel (a JA_* constant).
input.keyNumToName(int keynum) string Returns the name of the key specified by the key number keynum.
input.keyNameToNum(string keyname) int Returns the number of the key specified by the key name keyname.
input.keyNumPrintable(string keynum) boolean Returns whether the key specified by the key number keynum corresponds to a printable character.
input.shiftKeyNum(string keynum) int Returns the capitalized form of key number keynum.
input.getMouseGrab() boolean Returns whether the primary mouse is grabbed (locked and invisible) by the window.
input.setMouseGrab(boolean grab) nil Sets whether the primary mouse is grabbed (locked and invisible) by the window.

The mouse is automatically grabbed by the game in situations where it deems appropriate, so in order to keep the mouse ungrabbed this function may need to be called constantly.

input.getCursorPosition() int, int Returns the position of the cursor relative to the top-left corner of the window.

Constants

Miscellaneous constants

Name Value Description
JOYAXISRANGE 1023
The maximum magnitude for values returned by input.joyAxis and input.joyAxis2.

Joystick axis (JA_*)

Value Name Description
0 JA_NONE Null axis
1 JA_TURN Turn axis
2 JA_MOVE Move axis
3 JA_LOOK Vertical look axis
4 JA_STRAFE Side-step axis
5 JA_DIGITAL All axes below are digital rather than analog.
5 JA_JUMP Jump axis
6 JA_SPIN Spin axis
7 JA_FIRE Fire axis
8 JA_FIRENORMAL Normal fire axis

Mouse button flags (MB_*)

Decimal Hexadecimal Flag name Description
1 0x1 MB_BUTTON1 Mouse Button 1 (Left Click)
2 0x2 MB_BUTTON2 Mouse Button 2 (Right Click)
4 0x4 MB_BUTTON3 Mouse Button 3 (Middle Click)
8 0x8 MB_BUTTON4 Mouse Button 4
16 0x10 MB_BUTTON5 Mouse Button 5
32 0x20 MB_BUTTON6 Mouse Button 6
64 0x40 MB_BUTTON7 Mouse Button 7
128 0x80 MB_BUTTON8 Mouse Button 8
256 0x100 MB_SCROLLUP Scroll Up
512 0x200 MB_SCROLLDOWN Scroll Down

Game controls (GC_*)

Value Name Description
0 GC_NULL Unmapped
1 GC_FORWARD Move Forward
2 GC_BACKWARD Move Backward
3 GC_STRAFELEFT Move Left
4 GC_STRAFERIGHT Move Right
5 GC_TURNLEFT Look Left
6 GC_TURNRIGHT Look Right
7 GC_WEAPONNEXT Next Weapon
8 GC_WEAPONPREV Prev Weapon
9 GC_WEPSLOT1 Normal / Infinity
10 GC_WEPSLOT2 Automatic
11 GC_WEPSLOT3 Bounce
12 GC_WEPSLOT4 Scatter
13 GC_WEPSLOT5 Grenade
14 GC_WEPSLOT6 Explosion
15 GC_WEPSLOT7 Rail
16 GC_WEPSLOT8 Weapon Slot 8
17 GC_WEPSLOT9 Weapon Slot 9
18 GC_WEPSLOT10 Weapon Slot 10
19 GC_FIRE Fire
20 GC_FIRENORMAL Fire Normal
21 GC_TOSSFLAG Toss Flag
22 GC_SPIN Spin
23 GC_CAMTOGGLE Toggle Third-Person
24 GC_CAMRESET Reset Camera
25 GC_LOOKUP Look Up
26 GC_LOOKDOWN Look Down
27 GC_CENTERVIEW Center View
28 GC_MOUSEAIMING Toggle Mouselook
29 GC_TALKKEY Talk
30 GC_TEAMKEY Talk (Team only)
31 GC_SCORES Game Status
32 GC_JUMP Jump
33 GC_CONSOLE Console
34 GC_PAUSE Pause / Run Retry
35 GC_SYSTEMMENU Open/Close Menu (ESC)
36 GC_SCREENSHOT Screenshot
37 GC_RECORDGIF Toggle GIF Recording
38 GC_VIEWPOINT Change Viewpoint
39 GC_CUSTOM1 Custom Action 1
40 GC_CUSTOM2 Custom Action 2
41 GC_CUSTOM3 Custom Action 3
42 NUM_GAMECONTROLS Total number of game controls