Overview
Thekeybinds utility provides a robust input handling system that manages keyboard and mouse events, including key states, keybind callbacks, and mouse tracking. It processes Windows messages and maintains state for all input devices.
Usage
Access the global input manager:Global Instance
Global singleton instance of the input management system
Enumerations
key_state_t
Represents the state of a key or mouse button.No state / default state
Key is released
Key is pressed down
Key was just released (transient state, 100ms window)
Class: input::impl
Properties
Array tracking the state and timestamp of all 256 virtual key codes
Collection of registered keybind callbacks
Current mouse cursor position (x, y coordinates)
Current mouse scroll amount (positive = scroll up, negative = scroll down)
Methods
think
Processes Windows input messages and updates key states. Call this from your window procedure.Windows message type (WM_KEYDOWN, WM_MOUSEMOVE, etc.)
Message-specific parameter
Message-specific parameter
add_keybind
Registers a new keybind with a callback function.Virtual key code (e.g., VK_F1, VK_SPACE, VK_LBUTTON)
Function to call when the key state changes. Parameter is true when pressed, false when released.
remove_keybind
Removes all keybinds associated with a specific virtual key.Virtual key code to remove keybinds for
poll_keybind
Enters polling mode to wait for the user to press any key, useful for keybind configuration UIs.Function called when a valid key is pressed. Receives the virtual key code and pressed state.
Optional function called when polling is cancelled (ESC, mouse buttons)
key_state
Checks if a key is in a specific state.State to check for (KEY_UP, KEY_DOWN, KEY_RELEASED)
Virtual key code to check
True if the key is in the specified state
key_to_char
Converts a virtual key code to a human-readable string.Virtual key code to convert
String representation of the key (e.g., “F1”, “SPACE”, “LBUTTON”)
Mouse Functions
in_params (Coordinates)
Checks if the mouse cursor is within a rectangular area.X coordinate of the rectangle’s top-left corner
Y coordinate of the rectangle’s top-left corner
Width of the rectangle
Height of the rectangle
True if the mouse is within the specified rectangle
in_params (Vectors)
Checks if the mouse cursor is within a rectangular area using vector parameters.Position vector (x, y) of the rectangle’s top-left corner
Size vector (width, height) of the rectangle
True if the mouse is within the specified rectangle
Complete Examples
Supported Input Events
Thethink() method processes these Windows messages:
- Keyboard: WM_KEYDOWN, WM_KEYUP
- Mouse Buttons: WM_LBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP
- Extra Mouse Buttons: WM_XBUTTONDOWN, WM_XBUTTONUP (XBUTTON1, XBUTTON2)
- Mouse Movement: WM_MOUSEMOVE
- Mouse Wheel: WM_MOUSEWHEEL
- Focus: WM_KILLFOCUS, WM_SETFOCUS
The KEY_RELEASED state is transient and only returns true within 100ms of the key being released. This prevents missed release events in polling scenarios.