ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
asw::input Namespace Reference

Classes

struct  ControllerAxisBinding
 Binding to a controller axis, activated when the axis exceeds a threshold. More...
 
struct  ControllerButtonBinding
 Binding to a controller (gamepad) button. Set controller_index to ANY_CONTROLLER to accept every connected controller. More...
 
struct  KeyBinding
 Binding to a keyboard key. More...
 
struct  MouseButtonBinding
 Binding to a mouse button. More...
 

Typedefs

using ActionBinding = std::variant<KeyBinding, MouseButtonBinding, ControllerButtonBinding, ControllerAxisBinding>
 A single input binding — keyboard, mouse button, controller button, or controller axis.
 
using MouseState
 Mouse state stores the current state of the mouse. It is updated by the core.
 
using KeyState
 Keyboard state stores the current state of the keyboard. It is updated by the core.
 

Enumerations

enum class  MouseButton {
  Left = SDL_BUTTON_LEFT , Middle = SDL_BUTTON_MIDDLE , Right = SDL_BUTTON_RIGHT , X1 = SDL_BUTTON_X1 ,
  X2 = SDL_BUTTON_X2 , NumMouseButtons = NUM_MOUSE_BUTTONS
}
 Enumeration of mouse buttons in the ASW library. More...
 
enum class  Key {
  Unknown = SDL_SCANCODE_UNKNOWN , A = SDL_SCANCODE_A , B = SDL_SCANCODE_B , C = SDL_SCANCODE_C ,
  D = SDL_SCANCODE_D , E = SDL_SCANCODE_E , F = SDL_SCANCODE_F , G = SDL_SCANCODE_G ,
  H = SDL_SCANCODE_H , I = SDL_SCANCODE_I , J = SDL_SCANCODE_J , K = SDL_SCANCODE_K ,
  L = SDL_SCANCODE_L , M = SDL_SCANCODE_M , N = SDL_SCANCODE_N , O = SDL_SCANCODE_O ,
  P = SDL_SCANCODE_P , Q = SDL_SCANCODE_Q , R = SDL_SCANCODE_R , S = SDL_SCANCODE_S ,
  T = SDL_SCANCODE_T , U = SDL_SCANCODE_U , V = SDL_SCANCODE_V , W = SDL_SCANCODE_W ,
  X = SDL_SCANCODE_X , Y = SDL_SCANCODE_Y , Z = SDL_SCANCODE_Z , Num1 = SDL_SCANCODE_1 ,
  Num2 = SDL_SCANCODE_2 , Num3 = SDL_SCANCODE_3 , Num4 = SDL_SCANCODE_4 , Num5 = SDL_SCANCODE_5 ,
  Num6 = SDL_SCANCODE_6 , Num7 = SDL_SCANCODE_7 , Num8 = SDL_SCANCODE_8 , Num9 = SDL_SCANCODE_9 ,
  Num0 = SDL_SCANCODE_0 , Return = SDL_SCANCODE_RETURN , Escape = SDL_SCANCODE_ESCAPE , Backspace = SDL_SCANCODE_BACKSPACE ,
  Tab = SDL_SCANCODE_TAB , Space = SDL_SCANCODE_SPACE , Minus = SDL_SCANCODE_MINUS , Equals = SDL_SCANCODE_EQUALS ,
  LeftBracket = SDL_SCANCODE_LEFTBRACKET , RightBracket = SDL_SCANCODE_RIGHTBRACKET , Backslash = SDL_SCANCODE_BACKSLASH , NonUsHash = SDL_SCANCODE_NONUSHASH ,
  Semicolon = SDL_SCANCODE_SEMICOLON , Apostrophe = SDL_SCANCODE_APOSTROPHE , Grave = SDL_SCANCODE_GRAVE , Comma = SDL_SCANCODE_COMMA ,
  Period = SDL_SCANCODE_PERIOD , Slash = SDL_SCANCODE_SLASH , Capslock = SDL_SCANCODE_CAPSLOCK , F1 = SDL_SCANCODE_F1 ,
  F2 = SDL_SCANCODE_F2 , F3 = SDL_SCANCODE_F3 , F4 = SDL_SCANCODE_F4 , F5 = SDL_SCANCODE_F5 ,
  F6 = SDL_SCANCODE_F6 , F7 = SDL_SCANCODE_F7 , F8 = SDL_SCANCODE_F8 , F9 = SDL_SCANCODE_F9 ,
  F10 = SDL_SCANCODE_F10 , F11 = SDL_SCANCODE_F11 , F12 = SDL_SCANCODE_F12 , PrintScreen = SDL_SCANCODE_PRINTSCREEN ,
  ScrollLock = SDL_SCANCODE_SCROLLLOCK , Pause = SDL_SCANCODE_PAUSE , Insert = SDL_SCANCODE_INSERT , Home = SDL_SCANCODE_HOME ,
  PageUp = SDL_SCANCODE_PAGEUP , Delete = SDL_SCANCODE_DELETE , End = SDL_SCANCODE_END , PageDown = SDL_SCANCODE_PAGEDOWN ,
  Right = SDL_SCANCODE_RIGHT , Left = SDL_SCANCODE_LEFT , Down = SDL_SCANCODE_DOWN , Up = SDL_SCANCODE_UP ,
  NumLockClear = SDL_SCANCODE_NUMLOCKCLEAR , KpDivide = SDL_SCANCODE_KP_DIVIDE , KpMultiply = SDL_SCANCODE_KP_MULTIPLY , KpMinus = SDL_SCANCODE_KP_MINUS ,
  KpPlus = SDL_SCANCODE_KP_PLUS , KpEnter = SDL_SCANCODE_KP_ENTER , Kp1 = SDL_SCANCODE_KP_1 , Kp2 = SDL_SCANCODE_KP_2 ,
  Kp3 = SDL_SCANCODE_KP_3 , Kp4 = SDL_SCANCODE_KP_4 , Kp5 = SDL_SCANCODE_KP_5 , Kp6 = SDL_SCANCODE_KP_6 ,
  Kp7 = SDL_SCANCODE_KP_7 , Kp8 = SDL_SCANCODE_KP_8 , Kp9 = SDL_SCANCODE_KP_9 , Kp0 = SDL_SCANCODE_KP_0 ,
  KpPeriod = SDL_SCANCODE_KP_PERIOD , NonusBackslash = SDL_SCANCODE_NONUSBACKSLASH , Application = SDL_SCANCODE_APPLICATION , Power = SDL_SCANCODE_POWER ,
  KpEquals = SDL_SCANCODE_KP_EQUALS , F13 = SDL_SCANCODE_F13 , F14 = SDL_SCANCODE_F14 , F15 = SDL_SCANCODE_F15 ,
  F16 = SDL_SCANCODE_F16 , F17 = SDL_SCANCODE_F17 , F18 = SDL_SCANCODE_F18 , F19 = SDL_SCANCODE_F19 ,
  F20 = SDL_SCANCODE_F20 , F21 = SDL_SCANCODE_F21 , F22 = SDL_SCANCODE_F22 , F23 = SDL_SCANCODE_F23 ,
  F24 = SDL_SCANCODE_F24 , Execute = SDL_SCANCODE_EXECUTE , Help = SDL_SCANCODE_HELP , Menu = SDL_SCANCODE_MENU ,
  Select = SDL_SCANCODE_SELECT , Stop = SDL_SCANCODE_STOP , Again = SDL_SCANCODE_AGAIN , Undo = SDL_SCANCODE_UNDO ,
  Cut = SDL_SCANCODE_CUT , Copy = SDL_SCANCODE_COPY , Paste = SDL_SCANCODE_PASTE , Find = SDL_SCANCODE_FIND ,
  Mute = SDL_SCANCODE_MUTE , VolumeUp = SDL_SCANCODE_VOLUMEUP , VolumeDown = SDL_SCANCODE_VOLUMEDOWN , KpComma = SDL_SCANCODE_KP_COMMA ,
  KpEqualsSas400 = SDL_SCANCODE_KP_EQUALSAS400 , International1 = SDL_SCANCODE_INTERNATIONAL1 , International2 = SDL_SCANCODE_INTERNATIONAL2 , International3 = SDL_SCANCODE_INTERNATIONAL3 ,
  International4 = SDL_SCANCODE_INTERNATIONAL4 , International5 = SDL_SCANCODE_INTERNATIONAL5 , International6 = SDL_SCANCODE_INTERNATIONAL6 , International7 = SDL_SCANCODE_INTERNATIONAL7 ,
  International8 = SDL_SCANCODE_INTERNATIONAL8 , International9 = SDL_SCANCODE_INTERNATIONAL9 , Lang1 = SDL_SCANCODE_LANG1 , Lang2 = SDL_SCANCODE_LANG2 ,
  Lang3 = SDL_SCANCODE_LANG3 , Lang4 = SDL_SCANCODE_LANG4 , Lang5 = SDL_SCANCODE_LANG5 , Lang6 = SDL_SCANCODE_LANG6 ,
  Lang7 = SDL_SCANCODE_LANG7 , Lang8 = SDL_SCANCODE_LANG8 , Lang9 = SDL_SCANCODE_LANG9 , AltErase = SDL_SCANCODE_ALTERASE ,
  SysReq = SDL_SCANCODE_SYSREQ , Cancel = SDL_SCANCODE_CANCEL , Clear = SDL_SCANCODE_CLEAR , Prior = SDL_SCANCODE_PRIOR ,
  Return2 = SDL_SCANCODE_RETURN2 , Separator = SDL_SCANCODE_SEPARATOR , Out = SDL_SCANCODE_OUT , Oper = SDL_SCANCODE_OPER ,
  ClearAgain = SDL_SCANCODE_CLEARAGAIN , Crsel = SDL_SCANCODE_CRSEL , Exsel = SDL_SCANCODE_EXSEL , Kp00 = SDL_SCANCODE_KP_00 ,
  Kp000 = SDL_SCANCODE_KP_000 , ThousandsSeparator = SDL_SCANCODE_THOUSANDSSEPARATOR , DecimalSeparator = SDL_SCANCODE_DECIMALSEPARATOR , CurrencyUnit = SDL_SCANCODE_CURRENCYUNIT ,
  CurrencySubunit = SDL_SCANCODE_CURRENCYSUBUNIT , KpLeftParen = SDL_SCANCODE_KP_LEFTPAREN , KpRightParan = SDL_SCANCODE_KP_RIGHTPAREN , KpLeftBrace = SDL_SCANCODE_KP_LEFTBRACE ,
  KpRightBrace = SDL_SCANCODE_KP_RIGHTBRACE , KpTab = SDL_SCANCODE_KP_TAB , KpBackspace = SDL_SCANCODE_KP_BACKSPACE , KpA = SDL_SCANCODE_KP_A ,
  KpB = SDL_SCANCODE_KP_B , KpC = SDL_SCANCODE_KP_C , KpD = SDL_SCANCODE_KP_D , KpE = SDL_SCANCODE_KP_E ,
  KpF = SDL_SCANCODE_KP_F , KpXor = SDL_SCANCODE_KP_XOR , KpPower = SDL_SCANCODE_KP_POWER , KpPercent = SDL_SCANCODE_KP_PERCENT ,
  KpLess = SDL_SCANCODE_KP_LESS , KpGreater = SDL_SCANCODE_KP_GREATER , KpAmpersand = SDL_SCANCODE_KP_AMPERSAND , KpDoubleAmpersand = SDL_SCANCODE_KP_DBLAMPERSAND ,
  KpVerticalBar = SDL_SCANCODE_KP_VERTICALBAR , KpDoubleVerticalBar = SDL_SCANCODE_KP_DBLVERTICALBAR , KpColon = SDL_SCANCODE_KP_COLON , KpHash = SDL_SCANCODE_KP_HASH ,
  KpSpace = SDL_SCANCODE_KP_SPACE , KpAt = SDL_SCANCODE_KP_AT , KpExclam = SDL_SCANCODE_KP_EXCLAM , KpMemStore = SDL_SCANCODE_KP_MEMSTORE ,
  KpMemRecall = SDL_SCANCODE_KP_MEMRECALL , KpMemClear = SDL_SCANCODE_KP_MEMCLEAR , KpMemAdd = SDL_SCANCODE_KP_MEMADD , KpMemSubtract = SDL_SCANCODE_KP_MEMSUBTRACT ,
  KpMemMultiply = SDL_SCANCODE_KP_MEMMULTIPLY , KpMemDivide = SDL_SCANCODE_KP_MEMDIVIDE , KpPlusMinus = SDL_SCANCODE_KP_PLUSMINUS , KpClear = SDL_SCANCODE_KP_CLEAR ,
  KpClearEntry = SDL_SCANCODE_KP_CLEARENTRY , KpBinary = SDL_SCANCODE_KP_BINARY , KpOctal = SDL_SCANCODE_KP_OCTAL , KpDecimal = SDL_SCANCODE_KP_DECIMAL ,
  KpHexadecimal = SDL_SCANCODE_KP_HEXADECIMAL , LCtrl = SDL_SCANCODE_LCTRL , LShift = SDL_SCANCODE_LSHIFT , LAlt = SDL_SCANCODE_LALT ,
  LGui = SDL_SCANCODE_LGUI , RCtrl = SDL_SCANCODE_RCTRL , RShift = SDL_SCANCODE_RSHIFT , RAlt = SDL_SCANCODE_RALT ,
  RGui = SDL_SCANCODE_RGUI , Mode = SDL_SCANCODE_MODE , MediaNextTrack = SDL_SCANCODE_MEDIA_NEXT_TRACK , MediaPreviousTrack = SDL_SCANCODE_MEDIA_PREVIOUS_TRACK ,
  MediaStop = SDL_SCANCODE_MEDIA_STOP , MediaPlay = SDL_SCANCODE_MEDIA_PLAY , MediaSelect = SDL_SCANCODE_MEDIA_SELECT , AcSearch = SDL_SCANCODE_AC_SEARCH ,
  AcHome = SDL_SCANCODE_AC_HOME , AcBack = SDL_SCANCODE_AC_BACK , AcForward = SDL_SCANCODE_AC_FORWARD , AcStop = SDL_SCANCODE_AC_STOP ,
  AcRefresh = SDL_SCANCODE_AC_REFRESH , AcBookmarks = SDL_SCANCODE_AC_BOOKMARKS , Eject = SDL_SCANCODE_MEDIA_EJECT , Sleep = SDL_SCANCODE_SLEEP ,
  AudioRewind = SDL_SCANCODE_MEDIA_REWIND , AudioFastForward = SDL_SCANCODE_MEDIA_FAST_FORWARD , SoftLeft = SDL_SCANCODE_SOFTLEFT , SoftRight = SDL_SCANCODE_SOFTRIGHT ,
  Call = SDL_SCANCODE_CALL , EndCall = SDL_SCANCODE_ENDCALL , NumKeys = NUM_KEYS
}
 Enumeration of keys in the ASW library. More...
 
enum class  CursorId {
  Default = SDL_SYSTEM_CURSOR_DEFAULT , Text = SDL_SYSTEM_CURSOR_TEXT , Wait = SDL_SYSTEM_CURSOR_WAIT , Crosshair = SDL_SYSTEM_CURSOR_CROSSHAIR ,
  Progress = SDL_SYSTEM_CURSOR_PROGRESS , NwseResize = SDL_SYSTEM_CURSOR_NWSE_RESIZE , NeswResize = SDL_SYSTEM_CURSOR_NESW_RESIZE , EwResize = SDL_SYSTEM_CURSOR_EW_RESIZE ,
  NsResize = SDL_SYSTEM_CURSOR_NS_RESIZE , Move = SDL_SYSTEM_CURSOR_MOVE , NotAllowed = SDL_SYSTEM_CURSOR_NOT_ALLOWED , Pointer = SDL_SYSTEM_CURSOR_POINTER ,
  NwResize = SDL_SYSTEM_CURSOR_NW_RESIZE , NResize = SDL_SYSTEM_CURSOR_N_RESIZE , NeResize = SDL_SYSTEM_CURSOR_NE_RESIZE , EResize = SDL_SYSTEM_CURSOR_E_RESIZE ,
  SEResize = SDL_SYSTEM_CURSOR_SE_RESIZE , SResize = SDL_SYSTEM_CURSOR_S_RESIZE , SWResize = SDL_SYSTEM_CURSOR_SW_RESIZE , WResize = SDL_SYSTEM_CURSOR_W_RESIZE ,
  NumCursors = NUM_CURSORS
}
 System cursor Ids. More...
 
enum class  ControllerButton {
  A = SDL_GAMEPAD_BUTTON_SOUTH , B = SDL_GAMEPAD_BUTTON_EAST , X = SDL_GAMEPAD_BUTTON_WEST , Y = SDL_GAMEPAD_BUTTON_NORTH ,
  Back = SDL_GAMEPAD_BUTTON_BACK , Guide = SDL_GAMEPAD_BUTTON_GUIDE , Start = SDL_GAMEPAD_BUTTON_START , LeftStick = SDL_GAMEPAD_BUTTON_LEFT_STICK ,
  RightStick = SDL_GAMEPAD_BUTTON_RIGHT_STICK , LeftShoulder = SDL_GAMEPAD_BUTTON_LEFT_SHOULDER , RightShoulder = SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER , DPadUp = SDL_GAMEPAD_BUTTON_DPAD_UP ,
  DPadDown = SDL_GAMEPAD_BUTTON_DPAD_DOWN , DPadLeft = SDL_GAMEPAD_BUTTON_DPAD_LEFT , DPadRight = SDL_GAMEPAD_BUTTON_DPAD_RIGHT , Misc1 = SDL_GAMEPAD_BUTTON_MISC1 ,
  RightPaddle1 = SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1 , LeftPaddle1 = SDL_GAMEPAD_BUTTON_LEFT_PADDLE1 , RightPaddle2 = SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2 , LeftPaddle2 = SDL_GAMEPAD_BUTTON_LEFT_PADDLE2 ,
  TouchPad = SDL_GAMEPAD_BUTTON_TOUCHPAD , NumControllerButtons = NUM_CONTROLLER_BUTTONS
}
 Mappings from SDL game controller buttons to ASW buttons. More...
 
enum class  ControllerAxis {
  LeftX = SDL_GAMEPAD_AXIS_LEFTX , LeftY = SDL_GAMEPAD_AXIS_LEFTY , RightX = SDL_GAMEPAD_AXIS_RIGHTX , RightY = SDL_GAMEPAD_AXIS_RIGHTY ,
  LeftTrigger = SDL_GAMEPAD_AXIS_LEFT_TRIGGER , RightTrigger = SDL_GAMEPAD_AXIS_RIGHT_TRIGGER , NumControllerAxes = NUM_CONTROLLER_AXES
}
 Mappings from SDL game controller axes to ASW axes. More...
 
enum class  ControllerStick { Left , Right }
 Analog sticks on a game controller. More...
 
enum class  InputDevice { KeyboardMouse , Controller }
 Device the player used most recently. More...
 

Functions

void bind_action (std::string_view name, ActionBinding binding)
 Register a binding for a named action.
 
void unbind_action (std::string_view name)
 Remove all bindings for a named action.
 
void clear_actions ()
 Remove all registered actions and their bindings.
 
bool get_action_down (std::string_view name)
 Check if an action was triggered (first pressed) this frame.
 
bool get_action_up (std::string_view name)
 Check if an action was released this frame.
 
bool get_action (std::string_view name)
 Check if an action is currently held down.
 
float get_action_strength (std::string_view name)
 Get the analogue strength of an action (0.0 – 1.0).
 
void update_actions ()
 Update cached action states from current raw input.
 
const MouseState & get_mouse ()
 Get the current mouse state.
 
bool get_mouse_button (asw::input::MouseButton button)
 Check if a mouse button is down.
 
bool get_mouse_button_down (asw::input::MouseButton button)
 Check if a mouse button was pressed since the last update.
 
bool get_mouse_button_up (asw::input::MouseButton button)
 Check if a mouse button was released since the last update.
 
const KeyState & get_keyboard ()
 Get the current keyboard state.
 
bool get_key (asw::input::Key key)
 Check if a key is down.
 
bool get_key_down (asw::input::Key key)
 Check if a key was pressed since the last update.
 
bool get_key_repeat (asw::input::Key key)
 Check if a key was pressed or auto-repeated since the last update.
 
bool get_key_up (asw::input::Key key)
 Check if a key was released since the last update.
 
void set_cursor (asw::input::CursorId cursor)
 Change cursor.
 
void set_cursor_visible (bool visible)
 Show or hide the mouse cursor, for games that draw their own.
 
void simulate_key_down (asw::input::Key key)
 Simulate a key being pressed.
 
void simulate_key_up (asw::input::Key key)
 Simulate a key being released.
 
void simulate_mouse_move (const asw::Vec2< float > &position)
 Simulate the mouse moving.
 
void simulate_mouse_button_down (asw::input::MouseButton button)
 Simulate a mouse button being pressed.
 
void simulate_mouse_button_up (asw::input::MouseButton button)
 Simulate a mouse button being released.
 
bool get_controller_button (uint32_t index, asw::input::ControllerButton button)
 Check if a controller button is down.
 
bool get_controller_button_down (uint32_t index, asw::input::ControllerButton button)
 Check if a controller button was pressed since the last update.
 
bool get_controller_button_up (uint32_t index, asw::input::ControllerButton button)
 Check if a controller button was released since the last update.
 
float get_controller_axis (uint32_t index, asw::input::ControllerAxis axis)
 Get the value of a controller axis with the dead zone applied.
 
Vec2< float > get_controller_stick (uint32_t index, asw::input::ControllerStick stick)
 Get the position of a controller stick with the dead zone applied.
 
void set_controller_dead_zone (uint32_t index, float dead_zone)
 Set the joystick deadzone for a controller.
 
bool rumble_controller (uint32_t index, float low_frequency, float high_frequency, uint32_t duration_ms)
 Rumble a controller's main motors.
 
bool rumble_controller_triggers (uint32_t index, float left, float right, uint32_t duration_ms)
 Rumble a controller's trigger motors.
 
bool controller_has_rumble (uint32_t index)
 Check if a controller supports rumble.
 
bool controller_has_trigger_rumble (uint32_t index)
 Check if a controller supports trigger rumble.
 
InputDevice get_last_device ()
 Get the device the player used most recently.
 
int get_controller_count ()
 Get the number of controller slots.
 
bool is_controller_connected (uint32_t index)
 Check if a controller is connected at an index.
 
std::string get_controller_name (uint32_t index)
 Get the name of a controller.
 
const std::string & get_text_input ()
 Get the text input received this frame.
 
void reset ()
 Reset all input states. Called by the core.
 
void _shutdown ()
 Free cached cursors. Called by asw::core::shutdown().
 
void _append_text (const char *text)
 Event Hooks.
 
void _key_down (SDL_Scancode scancode, bool repeat=false)
 Key down hook.
 
void _key_up (SDL_Scancode scancode)
 Key up hook.
 
void _mouse_button_down (uint8_t button)
 Mouse button down hook.
 
void _mouse_button_up (uint8_t button)
 Mouse button up hook.
 
void _mouse_motion (float x, float y, float delta_x, float delta_y)
 Mouse motion hook.
 
void _mouse_wheel (float delta_z)
 Mouse wheel hook.
 
void _controller_added (SDL_JoystickID id)
 Controller added hook.
 
void _controller_removed (SDL_JoystickID id)
 Controller removed hook.
 
void _controller_axis_motion (SDL_JoystickID id, uint32_t axis, float value)
 Axis moved hook.
 
void _controller_button_down (SDL_JoystickID id, uint32_t button)
 Button down hook.
 
void _controller_button_up (SDL_JoystickID id, uint32_t button)
 Button up hook.
 

Variables

constexpr int NUM_MOUSE_BUTTONS = 6
 Number of mouse buttons in the ASW library.
 
constexpr int NUM_KEYS = SDL_SCANCODE_COUNT
 Number of keys in the ASW library.
 
constexpr int NUM_CURSORS = SDL_SYSTEM_CURSOR_COUNT
 Cursor count.
 
constexpr int NUM_CONTROLLER_BUTTONS = SDL_GAMEPAD_BUTTON_COUNT
 Number of buttons on a game controller.
 
constexpr int NUM_CONTROLLER_AXES = SDL_GAMEPAD_AXIS_COUNT
 Number of axes on a game controller.
 
constexpr uint32_t ANY_CONTROLLER = UINT32_MAX
 Pass as a controller index to read every connected controller.
 

Typedef Documentation

◆ ActionBinding

A single input binding — keyboard, mouse button, controller button, or controller axis.

Definition at line 65 of file action.h.

◆ KeyState

Initial value:
struct KeyState {
std::array<bool, NUM_KEYS> pressed { false };
std::array<bool, NUM_KEYS> released { false };
std::array<bool, NUM_KEYS> down { false };
std::array<bool, NUM_KEYS> repeated { false };
bool any_pressed { false };
int last_pressed { -1 };
}
struct KeyState { std::array< bool, NUM_KEYS > pressed { false }; std::array< bool, NUM_KEYS > released { false }; std::array< bool, NUM_KEYS > down { false }; std::array< bool, NUM_KEYS > repeated { false }; bool any_pressed { false }; int last_pressed { -1 };} KeyState
Keyboard state stores the current state of the keyboard. It is updated by the core.
Definition input.h:352

Keyboard state stores the current state of the keyboard. It is updated by the core.

Definition at line 352 of file input.h.

◆ MouseState

Initial value:
struct MouseState {
bool any_pressed { false };
int last_pressed { -1 };
Vec2<float> change { 0.0F, 0.0F };
Vec2<float> position { 0.0F, 0.0F };
float z { 0.0F };
std::array<bool, NUM_MOUSE_BUTTONS> pressed { false };
std::array<bool, NUM_MOUSE_BUTTONS> released { false };
std::array<bool, NUM_MOUSE_BUTTONS> down { false };
}
A 2D vector in space.
Definition geometry.h:27
struct MouseState { bool any_pressed { false }; int last_pressed { -1 }; Vec2< float > change { 0.0F, 0.0F }; Vec2< float > position { 0.0F, 0.0F }; float z { 0.0F }; std::array< bool, NUM_MOUSE_BUTTONS > pressed { false }; std::array< bool, NUM_MOUSE_BUTTONS > released { false }; std::array< bool, NUM_MOUSE_BUTTONS > down { false };} MouseState
Mouse state stores the current state of the mouse. It is updated by the core.
Definition input.h:306

Mouse state stores the current state of the mouse. It is updated by the core.

Definition at line 306 of file input.h.

Enumeration Type Documentation

◆ ControllerAxis

enum class asw::input::ControllerAxis
strong

Mappings from SDL game controller axes to ASW axes.

Enumerator
LeftX 
LeftY 
RightX 
RightY 
LeftTrigger 
RightTrigger 
NumControllerAxes 

Definition at line 488 of file input.h.

◆ ControllerButton

enum class asw::input::ControllerButton
strong

Mappings from SDL game controller buttons to ASW buttons.

Enumerator
A 
B 
X 
Y 
Back 
Guide 
Start 
LeftStick 
RightStick 
LeftShoulder 
RightShoulder 
DPadUp 
DPadDown 
DPadLeft 
DPadRight 
Misc1 
RightPaddle1 
LeftPaddle1 
RightPaddle2 
LeftPaddle2 
TouchPad 
NumControllerButtons 

Definition at line 459 of file input.h.

◆ ControllerStick

enum class asw::input::ControllerStick
strong

Analog sticks on a game controller.

Enumerator
Left 
Right 

Definition at line 506 of file input.h.

◆ CursorId

enum class asw::input::CursorId
strong

System cursor Ids.

Enumerator
Default 
Text 
Wait 
Crosshair 
Progress 
NwseResize 
NeswResize 
EwResize 
NsResize 
Move 
NotAllowed 
Pointer 
NwResize 
NResize 
NeResize 
EResize 
SEResize 
SResize 
SWResize 
WResize 
NumCursors 

Definition at line 280 of file input.h.

◆ InputDevice

enum class asw::input::InputDevice
strong

Device the player used most recently.

Enumerator
KeyboardMouse 
Controller 

Definition at line 512 of file input.h.

◆ Key

enum class asw::input::Key
strong

Enumeration of keys in the ASW library.

Enumerator
Unknown 
A 
B 
C 
D 
E 
F 
G 
H 
I 
J 
K 
L 
M 
N 
O 
P 
Q 
R 
S 
T 
U 
V 
W 
X 
Y 
Z 
Num1 
Num2 
Num3 
Num4 
Num5 
Num6 
Num7 
Num8 
Num9 
Num0 
Return 
Escape 
Backspace 
Tab 
Space 
Minus 
Equals 
LeftBracket 
RightBracket 
Backslash 
NonUsHash 
Semicolon 
Apostrophe 
Grave 
Comma 
Period 
Slash 
Capslock 
F1 
F2 
F3 
F4 
F5 
F6 
F7 
F8 
F9 
F10 
F11 
F12 
PrintScreen 
ScrollLock 
Pause 
Insert 
Home 
PageUp 
Delete 
End 
PageDown 
Right 
Left 
Down 
Up 
NumLockClear 
KpDivide 
KpMultiply 
KpMinus 
KpPlus 
KpEnter 
Kp1 
Kp2 
Kp3 
Kp4 
Kp5 
Kp6 
Kp7 
Kp8 
Kp9 
Kp0 
KpPeriod 
NonusBackslash 
Application 
Power 
KpEquals 
F13 
F14 
F15 
F16 
F17 
F18 
F19 
F20 
F21 
F22 
F23 
F24 
Execute 
Help 
Menu 
Select 
Stop 
Again 
Undo 
Cut 
Copy 
Paste 
Find 
Mute 
VolumeUp 
VolumeDown 
KpComma 
KpEqualsSas400 
International1 
International2 
International3 
International4 
International5 
International6 
International7 
International8 
International9 
Lang1 
Lang2 
Lang3 
Lang4 
Lang5 
Lang6 
Lang7 
Lang8 
Lang9 
AltErase 
SysReq 
Cancel 
Clear 
Prior 
Return2 
Separator 
Out 
Oper 
ClearAgain 
Crsel 
Exsel 
Kp00 
Kp000 
ThousandsSeparator 
DecimalSeparator 
CurrencyUnit 
CurrencySubunit 
KpLeftParen 
KpRightParan 
KpLeftBrace 
KpRightBrace 
KpTab 
KpBackspace 
KpA 
KpB 
KpC 
KpD 
KpE 
KpF 
KpXor 
KpPower 
KpPercent 
KpLess 
KpGreater 
KpAmpersand 
KpDoubleAmpersand 
KpVerticalBar 
KpDoubleVerticalBar 
KpColon 
KpHash 
KpSpace 
KpAt 
KpExclam 
KpMemStore 
KpMemRecall 
KpMemClear 
KpMemAdd 
KpMemSubtract 
KpMemMultiply 
KpMemDivide 
KpPlusMinus 
KpClear 
KpClearEntry 
KpBinary 
KpOctal 
KpDecimal 
KpHexadecimal 
LCtrl 
LShift 
LAlt 
LGui 
RCtrl 
RShift 
RAlt 
RGui 
Mode 
MediaNextTrack 
MediaPreviousTrack 
MediaStop 
MediaPlay 
MediaSelect 
AcSearch 
AcHome 
AcBack 
AcForward 
AcStop 
AcRefresh 
AcBookmarks 
Eject 
Sleep 
AudioRewind 
AudioFastForward 
SoftLeft 
SoftRight 
Call 
EndCall 
NumKeys 

Definition at line 38 of file input.h.

◆ MouseButton

enum class asw::input::MouseButton
strong

Enumeration of mouse buttons in the ASW library.

Enumerator
Left 
Middle 
Right 
X1 
X2 
NumMouseButtons 

Definition at line 28 of file input.h.

Function Documentation

◆ _append_text()

void asw::input::_append_text ( const char * text)

Event Hooks.

Append text to this frame's text input. Called by the core.

Definition at line 211 of file input.cpp.

◆ _controller_added()

void asw::input::_controller_added ( SDL_JoystickID id)

Controller added hook.

Definition at line 648 of file input.cpp.

◆ _controller_axis_motion()

void asw::input::_controller_axis_motion ( SDL_JoystickID id,
uint32_t axis,
float value )

Axis moved hook.

Definition at line 705 of file input.cpp.

◆ _controller_button_down()

void asw::input::_controller_button_down ( SDL_JoystickID id,
uint32_t button )

Button down hook.

Definition at line 724 of file input.cpp.

◆ _controller_button_up()

void asw::input::_controller_button_up ( SDL_JoystickID id,
uint32_t button )

Button up hook.

Definition at line 743 of file input.cpp.

◆ _controller_removed()

void asw::input::_controller_removed ( SDL_JoystickID id)

Controller removed hook.

Definition at line 683 of file input.cpp.

◆ _key_down()

void asw::input::_key_down ( SDL_Scancode scancode,
bool repeat = false )

Key down hook.

Event Hooks.

Parameters
scancodeThe key.
repeatWhether the event is an auto-repeat of a held key.

Definition at line 584 of file input.cpp.

◆ _key_up()

void asw::input::_key_up ( SDL_Scancode scancode)

Key up hook.

Definition at line 601 of file input.cpp.

◆ _mouse_button_down()

void asw::input::_mouse_button_down ( uint8_t button)

Mouse button down hook.

Definition at line 607 of file input.cpp.

◆ _mouse_button_up()

void asw::input::_mouse_button_up ( uint8_t button)

Mouse button up hook.

Definition at line 622 of file input.cpp.

◆ _mouse_motion()

void asw::input::_mouse_motion ( float x,
float y,
float delta_x,
float delta_y )

Mouse motion hook.

Definition at line 633 of file input.cpp.

◆ _mouse_wheel()

void asw::input::_mouse_wheel ( float delta_z)

Mouse wheel hook.

Definition at line 643 of file input.cpp.

◆ _shutdown()

void asw::input::_shutdown ( )

Free cached cursors. Called by asw::core::shutdown().

Definition at line 216 of file input.cpp.

◆ bind_action()

void asw::input::bind_action ( std::string_view name,
ActionBinding binding )

Register a binding for a named action.

Multiple bindings can be added to the same action; any active binding will satisfy the action (logical OR).

Parameters
nameThe action name.
bindingThe input binding to associate with the action.

Definition at line 151 of file action.cpp.

◆ clear_actions()

void asw::input::clear_actions ( )

Remove all registered actions and their bindings.

Definition at line 163 of file action.cpp.

◆ controller_has_rumble()

bool asw::input::controller_has_rumble ( uint32_t index)

Check if a controller supports rumble.

Parameters
indexThe index of the controller, or ANY_CONTROLLER.
Returns
true - If the controller (or any controller) supports rumble.
false - If it does not, or the index is invalid.

Definition at line 544 of file input.cpp.

◆ controller_has_trigger_rumble()

bool asw::input::controller_has_trigger_rumble ( uint32_t index)

Check if a controller supports trigger rumble.

Parameters
indexThe index of the controller, or ANY_CONTROLLER.
Returns
true - If the controller (or any controller) supports trigger rumble.
false - If it does not, or the index is invalid.

Definition at line 551 of file input.cpp.

◆ get_action()

bool asw::input::get_action ( std::string_view name)

Check if an action is currently held down.

Parameters
nameThe action name.
Returns
true if any binding is currently active.

Definition at line 180 of file action.cpp.

◆ get_action_down()

bool asw::input::get_action_down ( std::string_view name)

Check if an action was triggered (first pressed) this frame.

Parameters
nameThe action name.
Returns
true if any binding transitioned to active this frame.

Definition at line 168 of file action.cpp.

◆ get_action_strength()

float asw::input::get_action_strength ( std::string_view name)

Get the analogue strength of an action (0.0 – 1.0).

For button/key bindings this is 0 or 1. For axis bindings it is the normalised axis value clamped to the range [threshold, 1.0]. Returns the maximum strength across all active bindings.

Parameters
nameThe action name.
Returns
float Strength in [0.0, 1.0].

Definition at line 186 of file action.cpp.

◆ get_action_up()

bool asw::input::get_action_up ( std::string_view name)

Check if an action was released this frame.

Parameters
nameThe action name.
Returns
true if any binding transitioned to inactive this frame.

Definition at line 174 of file action.cpp.

◆ get_controller_axis()

float asw::input::get_controller_axis ( uint32_t index,
asw::input::ControllerAxis axis )

Get the value of a controller axis with the dead zone applied.

Stick axes use a radial dead zone, so a stick pushed straight along one axis reads zero on the other. Values past the dead zone are rescaled to start from zero.

Parameters
indexThe index of the controller to check, or ANY_CONTROLLER.
axisThe axis to check.
Returns
float - The value of the axis between -1.0f and 1.0f.

Definition at line 465 of file input.cpp.

◆ get_controller_button()

bool asw::input::get_controller_button ( uint32_t index,
asw::input::ControllerButton button )

Check if a controller button is down.

Parameters
indexThe index of the controller to check, or ANY_CONTROLLER.
buttonThe button to check.
Returns
true - If the button is down.
false - If the button is not down.

Definition at line 447 of file input.cpp.

◆ get_controller_button_down()

bool asw::input::get_controller_button_down ( uint32_t index,
asw::input::ControllerButton button )

Check if a controller button was pressed since the last update.

Parameters
indexThe index of the controller to check, or ANY_CONTROLLER.
buttonThe button to check.
Returns
true - If the button was pressed.
false - If the button was not pressed.

Definition at line 453 of file input.cpp.

◆ get_controller_button_up()

bool asw::input::get_controller_button_up ( uint32_t index,
asw::input::ControllerButton button )

Check if a controller button was released since the last update.

Parameters
indexThe index of the controller to check, or ANY_CONTROLLER.
buttonThe button to check.
Returns
true - If the button was released.
false - If the button was not released.

Definition at line 459 of file input.cpp.

◆ get_controller_count()

int asw::input::get_controller_count ( )

Get the number of controller slots.

Each pad keeps its index while other pads are unplugged. A pad plugged back in gets its old index, told apart by serial number, or by model when it has no serial. A new pad fills the first empty slot. So this is the highest connected index plus one, and 0 when no controller is connected.

Returns
int - The number of controller slots.

Definition at line 563 of file input.cpp.

◆ get_controller_name()

std::string asw::input::get_controller_name ( uint32_t index)

Get the name of a controller.

Definition at line 573 of file input.cpp.

◆ get_controller_stick()

asw::Vec2< float > asw::input::get_controller_stick ( uint32_t index,
asw::input::ControllerStick stick )

Get the position of a controller stick with the dead zone applied.

Parameters
indexThe index of the controller to check, or ANY_CONTROLLER.
stickThe stick to check.
Returns
Vec2<float> - The stick position, with a length of at most 1.

Definition at line 482 of file input.cpp.

◆ get_key()

bool asw::input::get_key ( asw::input::Key key)

Check if a key is down.

Parameters
keyThe key to check.
Returns
true - If the key is down.
false - If the key is not down.

Definition at line 423 of file input.cpp.

◆ get_key_down()

bool asw::input::get_key_down ( asw::input::Key key)

Check if a key was pressed since the last update.

Parameters
keyThe key to check.
Returns
true - If the key was pressed.
false - If the key was not pressed.

Definition at line 428 of file input.cpp.

◆ get_key_repeat()

bool asw::input::get_key_repeat ( asw::input::Key key)

Check if a key was pressed or auto-repeated since the last update.

A held key repeats at the rate the operating system sets. Use this for text editing and menu movement, and get_key_down() for game actions.

Parameters
keyThe key to check.
Returns
true - If the key was pressed or repeated.
false - If it was not.

Definition at line 433 of file input.cpp.

◆ get_key_up()

bool asw::input::get_key_up ( asw::input::Key key)

Check if a key was released since the last update.

Parameters
keyThe key to check.
Returns
true - If the key was released.
false - If the key was not released.

Definition at line 439 of file input.cpp.

◆ get_keyboard()

const asw::input::KeyState & asw::input::get_keyboard ( )

Get the current keyboard state.

Returns
Const reference to the current KeyState.

Definition at line 196 of file input.cpp.

◆ get_last_device()

asw::input::InputDevice asw::input::get_last_device ( )

Get the device the player used most recently.

Useful for showing keyboard or controller prompts. Key presses, mouse clicks and mouse motion count as the keyboard and mouse. Button presses and axes past the dead zone count as a controller.

Returns
InputDevice - The last used device.

Definition at line 558 of file input.cpp.

◆ get_mouse()

const asw::input::MouseState & asw::input::get_mouse ( )

Get the current mouse state.

Returns
Const reference to the current MouseState.

Definition at line 201 of file input.cpp.

◆ get_mouse_button()

bool asw::input::get_mouse_button ( asw::input::MouseButton button)

Check if a mouse button is down.

Parameters
buttonThe button to check.
Returns
true - If the button is down.
false - If the button is not down.

Definition at line 282 of file input.cpp.

◆ get_mouse_button_down()

bool asw::input::get_mouse_button_down ( asw::input::MouseButton button)

Check if a mouse button was pressed since the last update.

Parameters
buttonThe button to check.
Returns
true - If the button was pressed.
false - If the button was not pressed.

Definition at line 288 of file input.cpp.

◆ get_mouse_button_up()

bool asw::input::get_mouse_button_up ( asw::input::MouseButton button)

Check if a mouse button was released since the last update.

Parameters
buttonThe button to check.
Returns
true - If the button was released.
false - If the button was not released.

Definition at line 294 of file input.cpp.

◆ get_text_input()

const std::string & asw::input::get_text_input ( )

Get the text input received this frame.

Returns
Const reference to the text input string.

Definition at line 206 of file input.cpp.

◆ is_controller_connected()

bool asw::input::is_controller_connected ( uint32_t index)

Check if a controller is connected at an index.

Parameters
indexThe index of the controller.
Returns
true - If a controller is connected at the index.
false - If the slot is empty or the index is invalid.

Definition at line 568 of file input.cpp.

◆ reset()

void asw::input::reset ( )

Reset all input states. Called by the core.

Definition at line 226 of file input.cpp.

◆ rumble_controller()

bool asw::input::rumble_controller ( uint32_t index,
float low_frequency,
float high_frequency,
uint32_t duration_ms )

Rumble a controller's main motors.

Each call replaces the previous rumble on that controller. Call with both intensities at 0 to stop early.

Parameters
indexThe index of the controller, or ANY_CONTROLLER for all connected controllers.
low_frequencyIntensity of the low frequency (left) motor, between 0.0f and 1.0f.
high_frequencyIntensity of the high frequency (right) motor, between 0.0f and 1.0f.
duration_msHow long to rumble, in milliseconds.
Returns
true - If at least one controller started rumbling.
false - If no controller supports rumble or the index is invalid.

Definition at line 521 of file input.cpp.

◆ rumble_controller_triggers()

bool asw::input::rumble_controller_triggers ( uint32_t index,
float left,
float right,
uint32_t duration_ms )

Rumble a controller's trigger motors.

Only some controllers, such as Xbox One and Series controllers, have trigger motors. Each call replaces the previous trigger rumble on that controller. Call with both intensities at 0 to stop early.

Parameters
indexThe index of the controller, or ANY_CONTROLLER for all connected controllers.
leftIntensity of the left trigger motor, between 0.0f and 1.0f.
rightIntensity of the right trigger motor, between 0.0f and 1.0f.
duration_msHow long to rumble, in milliseconds.
Returns
true - If at least one controller started rumbling.
false - If no controller supports trigger rumble or the index is invalid.

Definition at line 532 of file input.cpp.

◆ set_controller_dead_zone()

void asw::input::set_controller_dead_zone ( uint32_t index,
float dead_zone )

Set the joystick deadzone for a controller.

Parameters
indexThe index of the controller, or ANY_CONTROLLER for all connected controllers and every controller connected later.
dead_zoneThe dead zone, between 0.0f and 1.0f. Defaults to 0.25f.

Definition at line 500 of file input.cpp.

◆ set_cursor()

void asw::input::set_cursor ( asw::input::CursorId cursor)

Change cursor.

Parameters
cursorThe cursor to change to.
windowThe window to change the cursor for.
Returns
true - If the cursor was changed.
false - If the cursor was not changed.

Definition at line 300 of file input.cpp.

◆ set_cursor_visible()

void asw::input::set_cursor_visible ( bool visible)

Show or hide the mouse cursor, for games that draw their own.

Parameters
visibleWhether the cursor is shown.

Definition at line 315 of file input.cpp.

◆ simulate_key_down()

void asw::input::simulate_key_down ( asw::input::Key key)

Simulate a key being pressed.

Simulated input

These queue the same events a real device sends, so they reach the game through the normal input path on the next core update. Use them to script demos or automated test runs.

Parameters
keyThe key.

Definition at line 374 of file input.cpp.

◆ simulate_key_up()

void asw::input::simulate_key_up ( asw::input::Key key)

Simulate a key being released.

Parameters
keyThe key.

Definition at line 379 of file input.cpp.

◆ simulate_mouse_button_down()

void asw::input::simulate_mouse_button_down ( asw::input::MouseButton button)

Simulate a mouse button being pressed.

Parameters
buttonThe button.

Definition at line 410 of file input.cpp.

◆ simulate_mouse_button_up()

void asw::input::simulate_mouse_button_up ( asw::input::MouseButton button)

Simulate a mouse button being released.

Parameters
buttonThe button.

Definition at line 415 of file input.cpp.

◆ simulate_mouse_move()

void asw::input::simulate_mouse_move ( const asw::Vec2< float > & position)

Simulate the mouse moving.

Parameters
positionThe new position in logical (render) coordinates, the same space get_mouse() reports.

Definition at line 384 of file input.cpp.

◆ unbind_action()

void asw::input::unbind_action ( std::string_view name)

Remove all bindings for a named action.

Parameters
nameThe action name to remove.

Definition at line 156 of file action.cpp.

◆ update_actions()

void asw::input::update_actions ( )

Update cached action states from current raw input.

Called automatically by asw::core::update() after events are processed — you do not need to call this yourself unless you are managing the input loop manually.

Definition at line 192 of file action.cpp.

Variable Documentation

◆ ANY_CONTROLLER

uint32_t asw::input::ANY_CONTROLLER = UINT32_MAX
constexpr

Pass as a controller index to read every connected controller.

Buttons are active if they are active on any controller. Axes and sticks return the value furthest from centre.

Definition at line 503 of file input.h.

◆ NUM_CONTROLLER_AXES

int asw::input::NUM_CONTROLLER_AXES = SDL_GAMEPAD_AXIS_COUNT
constexpr

Number of axes on a game controller.

Definition at line 485 of file input.h.

◆ NUM_CONTROLLER_BUTTONS

int asw::input::NUM_CONTROLLER_BUTTONS = SDL_GAMEPAD_BUTTON_COUNT
constexpr

Number of buttons on a game controller.

Definition at line 456 of file input.h.

◆ NUM_CURSORS

int asw::input::NUM_CURSORS = SDL_SYSTEM_CURSOR_COUNT
constexpr

Cursor count.

Definition at line 277 of file input.h.

◆ NUM_KEYS

int asw::input::NUM_KEYS = SDL_SCANCODE_COUNT
constexpr

Number of keys in the ASW library.

Definition at line 25 of file input.h.

◆ NUM_MOUSE_BUTTONS

int asw::input::NUM_MOUSE_BUTTONS = 6
constexpr

Number of mouse buttons in the ASW library.

Type defs

Definition at line 22 of file input.h.