sokol_input.h

Includes:
"sokol_app.h"
<stdarg.h>
<stdbool.h>
<string.h>
<stdint.h>
<stddef.h>
<assert.h>
<stdlib.h>

Introduction

Input handling for sokol_app

Discussion

Provides an input manager for sokol_app, handling keyboard, mouse, and gamepad input.

Updated:
Sunday, July 20, 2025


Functions

sapp_any_buttons_down

Check if any of the mouse buttons are currently pressed down.

sapp_any_keys_down

Check if any of the keys are currently pressed down.

sapp_are_buttons_down

Check if multiple mouse buttons are currently pressed down.

sapp_are_keys_down

Check if multiple keys are currently pressed down.

sapp_cursor_delta_x

Get the change in x position of the mouse cursor since the last frame.

sapp_cursor_delta_y

Get the change in y position of the mouse cursor since the last frame.

sapp_cursor_x

Get the current x position of the mouse cursor.

sapp_cursor_y

Get the current y position of the mouse cursor.

sapp_has_mouse_move

Check if the mouse has moved since the last frame.

sapp_input_event

Call this function to handle input events.

sapp_input_flush

Flush the input state.

sapp_input_init

Initialize the input system.

sapp_is_button_down

Check if a mouse button is currently pressed down.

sapp_is_key_down

Check if a key is currently pressed down.

sapp_modifier_down

Check if a specific modifier key is currently pressed down.

sapp_modifier_equals

Check if the current modifier keys match the specified ones.

sapp_scroll_x

Get the amount the mouse wheel has been scrolled in the x direction since the last frame.

sapp_scroll_y

Get the amount the mouse wheel has been scrolled in the y direction since the last frame.

sapp_was_button_pressed

Check if a mouse button was pressed down in the last frame.

sapp_was_button_released

Check if a mouse button was released in the last frame.

sapp_was_key_pressed

Check if a key was pressed down in the last frame.

sapp_was_key_released

Check if a key was released in the last frame.

sapp_was_mouse_scrolled

Check if the mouse wheel has been scrolled since the last frame.


sapp_any_buttons_down


Check if any of the mouse buttons are currently pressed down.

bool sapp_any_buttons_down(
    int n,
    ...);  
Parameters
n

The number of buttons to check.

...

The mouse button codes to check.

Return Value

True if any of the buttons are currently pressed down.


sapp_any_keys_down


Check if any of the keys are currently pressed down.

bool sapp_any_keys_down(
    int n,
    ...);  
Parameters
n

The number of keys to check.

...

The key codes to check.

Return Value

True if any of the keys are currently pressed down.


sapp_are_buttons_down


Check if multiple mouse buttons are currently pressed down.

bool sapp_are_buttons_down(
    int n,
    ...);  
Parameters
n

The number of buttons to check.

...

The mouse button codes to check.

Return Value

True if all the buttons are currently pressed down.


sapp_are_keys_down


Check if multiple keys are currently pressed down.

bool sapp_are_keys_down(
    int n,
    ...);  
Parameters
n

The number of keys to check.

...

The key codes to check.

Return Value

True if all the keys are currently pressed down.


sapp_cursor_delta_x


Get the change in x position of the mouse cursor since the last frame.

int sapp_cursor_delta_x(
    void);  
Return Value

The change in x position of the mouse cursor since the last frame.


sapp_cursor_delta_y


Get the change in y position of the mouse cursor since the last frame.

int sapp_cursor_delta_y(
    void);  
Return Value

The change in y position of the mouse cursor since the last frame.


sapp_cursor_x


Get the current x position of the mouse cursor.

int sapp_cursor_x(
    void);  
Return Value

The current x position of the mouse cursor.


sapp_cursor_y


Get the current y position of the mouse cursor.

int sapp_cursor_y(
    void);  
Return Value

The current y position of the mouse cursor.


sapp_has_mouse_move


Check if the mouse has moved since the last frame.

bool sapp_has_mouse_move(
    void);  
Return Value

True if the mouse has moved since the last frame.


sapp_input_event


Call this function to handle input events.

void sapp_input_event(
    const sapp_event *event);  
Parameters
event

The input event to process.

Discussion

This function should be called in the sapp event callback to process input events. Or it can be used directly by passing it as the event handler in sapp_run.


sapp_input_flush


Flush the input state.

void sapp_input_flush(
    void);  
Discussion

Call this function at the end of each frame to update the input state.


sapp_input_init


Initialize the input system.

void sapp_input_init(
    void);  
Discussion

Call this function to initialize the input system. Either before sapp_run or in the sapp init callback.


sapp_is_button_down


Check if a mouse button is currently pressed down.

bool sapp_is_button_down(
    int button);  
Parameters
button

The mouse button to check.

Return Value

True if the mouse button is currently pressed down.


sapp_is_key_down


Check if a key is currently pressed down.

bool sapp_is_key_down(
    int key);  
Parameters
key

The key code to check.

Return Value

True if the key is currently pressed down.


sapp_modifier_down


Check if a specific modifier key is currently pressed down.

bool sapp_modifier_down(
    int mod);  
Parameters
mod

The modifier key to check.

Return Value

True if the specified modifier key is currently pressed down.


sapp_modifier_equals


Check if the current modifier keys match the specified ones.

bool sapp_modifier_equals(
    int mods);  
Parameters
mods

The modifier keys to check.

Return Value

True if the current modifiers match the specified ones.


sapp_scroll_x


Get the amount the mouse wheel has been scrolled in the x direction since the last frame.

float sapp_scroll_x(
    void);  
Return Value

The amount the mouse wheel has been scrolled in the x direction since the last frame.


sapp_scroll_y


Get the amount the mouse wheel has been scrolled in the y direction since the last frame.

float sapp_scroll_y(
    void);  
Return Value

The amount the mouse wheel has been scrolled in the y direction since the last frame.


sapp_was_button_pressed


Check if a mouse button was pressed down in the last frame.

bool sapp_was_button_pressed(
    int button);  
Parameters
button

The mouse button to check.

Return Value

True if the mouse button was pressed down in the last frame.


sapp_was_button_released


Check if a mouse button was released in the last frame.

bool sapp_was_button_released(
    int button);  
Parameters
button

The mouse button to check.

Return Value

True if the mouse button was released in the last frame.


sapp_was_key_pressed


Check if a key was pressed down in the last frame.

bool sapp_was_key_pressed(
    int key);  
Parameters
key

The key code to check.

Return Value

True if the key was pressed down in the last frame.


sapp_was_key_released


Check if a key was released in the last frame.

bool sapp_was_key_released(
    int key);  
Parameters
key

The key code to check.

Return Value

True if the key was released in the last frame.


sapp_was_mouse_scrolled


Check if the mouse wheel has been scrolled since the last frame.

bool sapp_was_mouse_scrolled(
    void);  
Return Value

True if the mouse wheel has been scrolled since the last frame.