Skip to main content

Working with input maps

WIP Input Map UI

Current priority of the engine is to provide a table based UI to define the input commands, bindings, and schemes. In the meantime, you can use the input map by modifying the YAML file directly.

What are input maps?

Input map is a custom asset type that is used to map raw system inputs to logical commands. Input maps consist of three sets of elements -- schemes, commands, and bindings. Example:

schemes:
- name: Explore
- name: Combat
commands:
- name: Move
data: axis-2d
- name: Hit
data: boolean
- name: Pick
data: boolean
bindings:
- scheme: 0
command: 2
binding: MOUSE_LEFT
- scheme: 1
command: 3
binding: MOUSE_LEFT
- scheme: 0
command: 0
binding:
x: [KEY_A, KEY_D]
y: [KEY_W, KEY_S]
- scheme: 0
command: 0
binding:
x: GAMEPAD_LEFT_X
y: GAMEPAD_LEFT_Y

Commands

Commands are logical representations of commands that developer intends to do based on commands. Commands contain two properties: Name and data type.

  • Name: Unique name of the command. Command names are used to find the needed command from scripts to retrieve input operation.
  • Data type: Data type represents what value the command stores given input.

Data types

There are three types of commands that exist in the input system:

  • boolean: Represent true/false value. Useful to check whether a key is pressed
  • axis-1d: Represents axis in one direction between [-1.0, 1.0]. Gamepad thumbsticks are one-dimensional. axis
  • axis-2d: Represents x and y axes as two axis-1d values.

Note that, the command types can only be boolean and axis-2d but each input key represents one of the three values.

Schemes

Schemes provide additional dimension to bindings. The main purpose of scheme is to map the same binding to more than one command. This is useful when we want to perform different actions depending on some specific trigger. The scheme data is very generic and one can perform mappings depending on their use-case. For example, you can use schemes to separate between gamepad and keyboard/mouse by storing bindings for each input type in different schemes. You can also use schemes to trigger between different command sets. For example, you can choose between shooting arrow vs meleeing, depending on "arrow drawn" command being executed.

The input map must always have at least one scheme available.

Bindings

Bindings provide a mapping between input keys and the logical commands that we provide. A typical binding is stored in the following way:

- scheme: 0
command: 0
binding:
x: GAMEPAD_LEFT_X
y: GAMEPAD_LEFT_Y

A binding must reference the scheme and the command stored in the input map asset.

Binding values

The binding value differs depending on the command data type.

Axis 2D

Axis 2D values can be defined in three ways:

Passing Axis 2D key directly:

binding: MOUSE_MOVE

MOUSE_MOVE is an Axis 2D key; so, we can directly pass it to a binding that references axis-2d command.

Passing Axis 1D key to each axis separately:

binding:
x: GAMEPAD_LEFT_X
y: GAMEPAD_LEFT_Y

GAMEPAD_LEFT_X/Y are Axis 1D keys; so, you can pass each one to a different axis of a binding that references axis-2d command.

Passing boolean keys to each segment of each axis:

binding:
x: [KEY_A, KEY_D]
y: [KEY_W, KEY_S]

KEY_A/D/W/S are boolean keys; so, they can be passed to represent each end of an axis. In the example above, pressing the keys will result in fixed values:

axiskeyvalue on pressdirection
xKEY_A-1.0left
xKEY_D1.0right
yKEY_W-1.0top
yKEY_S1.0bottom

Having top as -1.0 might seem unintuitive at first but it is designed with to map to gamepad keys vis-a-vis, which makes it easier to provide both bindings for the same command:

schemes:
- name: Default

commands:
- name: Move
type: axis-2d

bindings:
- scheme: 0
command: 0
binding:
x: [KEY_A, KEY_D]
y: [KEY_W, KEY_S]
- scheme: 0
command: 0
binding:
x: GAMEPAD_LEFT_X
y: GAMEPAD_LEFT_Y

In the example above pressing 'W' or moving the left thumbstick to top provides negative values in y direction. Pressing 'D' or moving the left thumbstick to right, provides positive values in x direction.

Key bindings

Here is the table for all the supported keys:

Keyboard:

Key stringRepresentationType
KEY_[A-Z][A-Z]Boolean
KEY_[0-9][0-9]Boolean
KEY_COMMA,Boolean
KEY_MINUS-Boolean
KEY_PERIOD.Boolean
KEY_SLASH/Boolean
KEY_SEMICOLON;Boolean
KEY_EQUAL=Boolean
KEY_LEFT_BRACKET[Boolean
KEY_BACKSLASH\Boolean
KEY_RIGHT_BRACKET]Boolean
KEY_GRAVE_ACCENT```Boolean
KEY_SPACESpacebarBoolean
KEY_ESCAPEEscapeBoolean
KEY_ENTEREnterBoolean
KEY_TABTabBoolean
KEY_BACKSPACEBackspaceBoolean
KEY_INSERTInsert keyBoolean
KEY_DELETEDelete keyBoolean
KEY_RIGHTRight arrowBoolean
KEY_LEFTLeft arrowBoolean
KEY_DOWNDown arrowBoolean
KEY_UPUp arrowBoolean
KEY_PAGE_UPPage upBoolean
KEY_PAGE_DOWNPage downBoolean
KEY_HOMEHomeBoolean
KEY_ENDEndBoolean
KEY_CAPS_LOCKCaps lockBoolean
KEY_SCROLL_LOCKScroll lockBoolean
KEY_NUM_LOCKNum lockBoolean
KEY_PRINT_SCREENPrint screenBoolean
KEY_PAUSEPauseBoolean
KEY_LEFT_SHIFTLeft shiftBoolean
KEY_LEFT_CONTROLLeft controlBoolean
KEY_LEFT_ALTLeft altBoolean
KEY_LEFT_SUPERLeft Win/CMD keyBoolean
KEY_RIGHT_SHIFTRight shiftBoolean
KEY_RIGHT_CONTROLRight controlBoolean
KEY_RIGHT_ALTRight altBoolean
KEY_RIGHT_SUPERRight Win/CMD keyBoolean

Mouse:

Key stringRepresentationType
MOUSE_LEFTLeft mouse buttonBoolean
MOUSE_RIGHTRight mouse buttonBoolean
MOUSE_MIDDLEMiddle mouse buttonBoolean
MOUSE_MOVEMouse movementAxis 2D

Gamepad:

Key stringXboxDualshock/senseType
GAMEPAD_SOUTHACross (X)Boolean
GAMEPAD_EASTBCircleBoolean
GAMEPAD_WESTXSquareBoolean
GAMEPAD_NORTHYTriangleBoolean
GAMEPAD_BUMPER_LEFTLBL1Boolean
GAMEPAD_BUMPER_RIGHTRBR1Boolean
GAMEPAD_TRIGGER_LEFTLTL2Boolean
GAMEPAD_TRIGGER_RIGHTRTR2Boolean
GAMEPAD_THUMB_LEFTLSBL3 / LSBBoolean
GAMEPAD_THUMB_RIGHTRSBR3 / RSBBoolean
GAMEPAD_DPAD_UPDpad upDpad upBoolean
GAMEPAD_DPAD_RIGHTDpad rightDpad rightBoolean
GAMEPAD_DPAD_LEFTDpad leftDpad leftBoolean
GAMEPAD_DPAD_DOWNDpad downDpad downBoolean
GAMEPAD_LEFT_XLeft thumbstick horizontalLeft thumbstick horizontalAxis 1D
GAMEPAD_LEFT_YLeft thumbstick verticalLeft thumbstick verticalAxis 1D
GAMEPAD_RIGHT_YRight thumbstick horizontalRight thumbstick horizontalAxis 1D
GAMEPAD_RIGHT_YRight thumbstick verticalRight thumbstick verticalAxis 1D
GAMEPAD_STARTStart buttonStart buttonAxis 1D
GAMEPAD_BACKBack buttonBack buttonAxis 1D