Input consts

This module contains key codes for constants used to handle input states from buttons on the keyboard and gamepad (Xbox controller). There is also a type, KeyboardShifts, for uniform processing of duplicate keys such as SHIFT, CTRL, and ALT.

To add this module to your project, add the following line to your project file:

require engine.input_core // or require engine.core

Type aliases

bitfield GamepadButtons

Button codes for gamepad (Xbox) controller

Fields:
  • Up (0x1) - Up on Xbox controller

  • Down (0x2) - Down on Xbox controller

  • Left (0x4) - Left on Xbox controller

  • Right (0x8) - Right on Xbox controller

  • Start (0x10) - Start on Xbox controller, hidden for engine use, do not bind actions to this button

  • Back (0x20) - Back on Xbox controller

  • L3 (0x40) - L3 (LSB or Left Stick) on Xbox controller

  • R3 (0x80) - R3 (RSB or Right Stick) on Xbox controller

  • LeftBumper (0x100) - LB on Xbox controller

  • RightBumper (0x200) - RB on Xbox controller

  • RESERVED1 (0x400) - unused placeholder

  • RESERVED2 (0x800) - unused placeholder

  • A (0x1000) - A on Xbox controller

  • B (0x2000) - B on Xbox controller

  • X (0x4000) - X on Xbox controller

  • Y (0x8000) - Y on Xbox controller

  • LeftTrigger (0x10000) - LT (or Left Trigger) on Xbox controller

  • RightTrigger (0x20000) - RT (or Right Trigger) on Xbox controller

bitfield KeyboardShifts : uint8

Raw keyboard shift states

Fields:
  • LShift (0x1) - Left shift

  • RShift (0x2) - Right shift

  • LCtrl (0x4) - Left control

  • RCtrl (0x8) - Right control

  • LAlt (0x10) - Left alt

  • RAlt (0x20) - Right alt

  • Shift (0x3) - Left or right shift

  • Ctrl (0xc) - Left or right control

  • Alt (0x30) - Left or right alt

bitfield ActiveStateMask : uint8

Mask with bits set for each type of input that has any non-default value during the current frame: button pressed, sticks and triggers touched or mouse moved

Fields:
  • KeyboardButton (0x1) - Any keyboard button is pressed

  • MouseButton (0x2) - Any mouse button is pressed

  • GamepadButton (0x4) - Any gamepad button is pressed

  • GamepadStick (0x8) - Any gamepad stick is touched (has non-zero value)

  • GamepadSlider (0x10) - Any gamepad slider is touched (has non-zero value)

  • MouseMove (0x20) - The mouse has moved since the last frame

bitfield JustPressedMask : uint8

Mask with bits set for each type of button that was just pressed during the current frame. For example, if any keyboard button was just pressed, the KeyboardButton bit will be set.

Fields:
  • KeyboardButton (0x1) - Any keyboard button was just pressed

  • MouseButton (0x2) - Any mouse button was just pressed

  • GamepadButton (0x4) - Any gamepad button was just pressed

bitfield JustReleasedMask : uint8

Mask with bits set for each type of button that was just released during the current frame. For example, if any mouse button was just released, the MouseButton bit will be set.

Fields:
  • KeyboardButton (0x1) - Any keyboard button was just released

  • MouseButton (0x2) - Any mouse button was just released

  • GamepadButton (0x4) - Any gamepad button was just released

Enumerations

ControllerIndex

Indices of gamepad controllers

Values:
  • Device0 = 0x0 - First controller

  • Device1 = 0x1 - Second controller

  • Device2 = 0x2 - Third controller

  • Device3 = 0x3 - Fourth controller

  • Device4 = 0x4 - Fifth controller

  • Device5 = 0x5 - Sixth controller

  • Device6 = 0x6 - Seventh controller

  • Device7 = 0x7 - Eighth controller

GamepadButton

Button code for one button on gamepad (Xbox) controller

Values:
  • Up = 0x0 - Up on Xbox controller

  • Down = 0x1 - Down on Xbox controller

  • Left = 0x2 - Left on Xbox controller

  • Right = 0x3 - Right on Xbox controller

  • Start = 0x4 - Start on Xbox controller, hidden for engine use, do not bind actions to this button

  • Back = 0x5 - Back on Xbox controller

  • L3 = 0x6 - L3 (LSB or Left Stick) on Xbox controller

  • R3 = 0x7 - R3 (RSB or Right Stick) on Xbox controller

  • LeftBumper = 0x8 - LB on Xbox controller

  • RightBumper = 0x9 - RB on Xbox controller

  • A = 0xc - A on Xbox controller

  • B = 0xd - B on Xbox controller

  • X = 0xe - X on Xbox controller

  • Y = 0xf - Y on Xbox controller

  • LeftTrigger = 0x10 - LT (or Left Trigger) on Xbox controller

  • RightTrigger = 0x11 - RT (or Right Trigger) on Xbox controller

KeyCode

Virtual key codes for keyboard buttons

Values:
  • Escape = 0x1 - Escape key, hidden for engine use, do not bind actions to this key

  • _1 = 0x2 - 1 on main keyboard

  • _2 = 0x3 - 2 on main keyboard

  • _3 = 0x4 - 3 on main keyboard

  • _4 = 0x5 - 4 on main keyboard

  • _5 = 0x6 - 5 on main keyboard

  • _6 = 0x7 - 6 on main keyboard

  • _7 = 0x8 - 7 on main keyboard

  • _8 = 0x9 - 8 on main keyboard

  • _9 = 0xa - 9 on main keyboard

  • _0 = 0xb - 0 on main keyboard

  • Minus = 0xc - - on main keyboard

  • Equals = 0xd - = on main keyboard

  • Back = 0xe - backspace

  • Tab = 0xf - tab

  • Q = 0x10 - Q

  • W = 0x11 - W

  • E = 0x12 - E

  • R = 0x13 - R

  • T = 0x14 - T

  • Y = 0x15 - Y

  • U = 0x16 - U

  • I = 0x17 - I

  • O = 0x18 - O

  • P = 0x19 - P

  • LBracket = 0x1a - [

  • RBracket = 0x1b - ]

  • Return = 0x1c - Enter on main keyboard

  • LControl = 0x1d - Left Control

  • A = 0x1e - A

  • S = 0x1f - S

  • D = 0x20 - D

  • F = 0x21 - F

  • G = 0x22 - G

  • H = 0x23 - H

  • J = 0x24 - J

  • K = 0x25 - K

  • L = 0x26 - L

  • Semicolon = 0x27 - ;

  • Apostrophe = 0x28 - '

  • Grave = 0x29 - ` accent grave

  • LShift = 0x2a - Left Shift

  • Backslash = 0x2b - \ on main keyboard

  • Z = 0x2c - Z

  • X = 0x2d - X

  • C = 0x2e - C

  • V = 0x2f - V

  • B = 0x30 - B

  • N = 0x31 - N

  • M = 0x32 - M

  • Comma = 0x33 - , on main keyboard

  • Period = 0x34 - . on main keyboard

  • Slash = 0x35 - / on main keyboard

  • RShift = 0x36 - Right Shift

  • Rshift = 0x36 - Right Shift (deprecated key code, use RShift instead)

  • Multiply = 0x37 - * on numeric keypad

  • LAlt = 0x38 - Left Alt

  • Space = 0x39 - Spacebar

  • Capital = 0x3a - Caps Lock

  • F1 = 0x3b - F1

  • F2 = 0x3c - F2

  • F3 = 0x3d - F3

  • F4 = 0x3e - F4

  • F5 = 0x3f - F5

  • F6 = 0x40 - F6

  • F7 = 0x41 - F7

  • F8 = 0x42 - F8

  • F9 = 0x43 - F9

  • F10 = 0x44 - F10

  • Numlock = 0x45 - Num Lock

  • Scroll = 0x46 - Scroll Lock

  • Numpad7 = 0x47 - 7 on numeric keypad

  • Numpad8 = 0x48 - 8 on numeric keypad

  • Numpad9 = 0x49 - 9 on numeric keypad

  • Subtract = 0x4a - - on numeric keypad

  • Numpad4 = 0x4b - 4 on numeric keypad

  • Numpad5 = 0x4c - 5 on numeric keypad

  • Numpad6 = 0x4d - 6 on numeric keypad

  • Add = 0x4e - + on numeric keypad

  • Numpad1 = 0x4f - 1 on numeric keypad

  • Numpad2 = 0x50 - 2 on numeric keypad

  • Numpad3 = 0x51 - 3 on numeric keypad

  • Numpad0 = 0x52 - 0 on numeric keypad

  • Decimal = 0x53 - . on numeric keypad

  • Oem102 = 0x56 - <> or \| on RT 102-key keyboard (Non-U.S.)

  • F11 = 0x57 - F11

  • F12 = 0x58 - F12

  • F13 = 0x64 - F13 (NEC PC98)

  • F14 = 0x65 - F14 (NEC PC98)

  • F15 = 0x66 - F15 (NEC PC98)

  • KANA = 0x70 - (Japanese keyboard)

  • ABNT_C1 = 0x73 - /? on Brazilian keyboard

  • CONVERT = 0x79 - (Japanese keyboard)

  • NOCONVERT = 0x7b - (Japanese keyboard)

  • YEN = 0x7d - (Japanese keyboard)

  • ABNT_C2 = 0x7e - Numpad . on Brazilian keyboard

  • NumpadEquals = 0x8d - = on numeric keypad (NEC PC98)

  • PrevTrack = 0x90 - Previous Track (DIK_CIRCUMFLEX on Japanese keyboard)

  • At = 0x91 - (NEC PC98)

  • Colon = 0x92 - (NEC PC98)

  • Underline = 0x93 - (NEC PC98)

  • Kanji = 0x94 - (Japanese keyboard)

  • Stop = 0x95 - (NEC PC98)

  • Ax = 0x96 - (Japan AX)

  • Unlabeled = 0x97 - (J3100)

  • NextTrack = 0x99 - Next Track

  • NumpadEnter = 0x9c - Enter on numeric keypad

  • RControl = 0x9d - Right Control

  • Mute = 0xa0 - Mute

  • Calculator = 0xa1 - Calculator

  • PlayPause = 0xa2 - Play / Pause

  • MediaStop = 0xa4 - Media Stop

  • VolumeDown = 0xae - Volume -

  • VolumeUp = 0xb0 - Volume +

  • Webhome = 0xb2 - Web home

  • NumpadComma = 0xb3 - , on numeric keypad (NEC PC98)

  • Divide = 0xb5 - / on numeric keypad

  • Print = 0xb7 - System Request / Print Screen

  • RAlt = 0xb8 - Right Alt

  • Pause = 0xc5 - Pause

  • Home = 0xc7 - Home on arrow keypad

  • Up = 0xc8 - UpArrow on arrow keypad

  • Prior = 0xc9 - PgUp on arrow keypad

  • Left = 0xcb - LeftArrow on arrow keypad

  • Right = 0xcd - RightArrow on arrow keypad

  • End = 0xcf - End on arrow keypad

  • Down = 0xd0 - DownArrow on arrow keypad

  • Next = 0xd1 - PgDn on arrow keypad

  • Insert = 0xd2 - Insert on arrow keypad

  • Delete = 0xd3 - Delete on arrow keypad

  • LWin = 0xdb - Left Windows key

  • RWin = 0xdc - Right Windows key

  • Apps = 0xdd - AppMenu key

MouseButton

Mouse buttons

Values:
  • Left = 0x0 - left mouse button

  • Right = 0x1 - right mouse button

  • Middle = 0x2 - middle mouse button (scroll wheel)

  • WheelUp = 0x5 - mouse wheel up

  • WheelDown = 0x6 - mouse wheel down

Functions

ControllerIndex(idx: int): ControllerIndex

Converts an integer to a controller index enum

Arguments:
  • idx : int

GamepadButton&(a: GamepadButton; b: GamepadButtons): GamepadButtons

Bitwise AND operator for GamepadButton and GamepadButtons

Arguments:
GamepadButtons&(a: GamepadButtons; b: GamepadButton): GamepadButtons

Bitwise AND operator for GamepadButtons and GamepadButton

Arguments: