Skip to main content

Input Handling

The libghostty input API provides functions and types for handling keyboard and mouse events.

Keyboard Input

ghostty_surface_key

Sends a keyboard event to the surface.
surface
ghostty_surface_t
required
The surface to send the key event to.
key
ghostty_input_key_s
required
The key event data.
Returns: true if the key was handled, false otherwise. Example:

ghostty_surface_key_is_binding

Checks if a key is bound to an action.
surface
ghostty_surface_t
required
The surface to check.
key
ghostty_input_key_s
required
The key to check.
flags
ghostty_binding_flags_e*
Optional pointer to receive binding flags.
Returns: true if the key is bound to an action.

ghostty_surface_text

Sends text directly to the surface (for IME or pasted text).
surface
ghostty_surface_t
required
The surface to send text to.
text
const char*
required
The text to send.
len
uintptr_t
required
Length of the text in bytes.

ghostty_surface_preedit

Sends IME pre-edit text to the surface.
surface
ghostty_surface_t
required
The surface.
text
const char*
required
The pre-edit text.
len
uintptr_t
required
Length of the text.

ghostty_surface_ime_point

Gets the screen coordinates for IME candidate window positioning.
surface
ghostty_surface_t
required
The surface.
x
double*
required
Pointer to store X coordinate.
y
double*
required
Pointer to store Y coordinate.
width
double*
required
Pointer to store width.
height
double*
required
Pointer to store height.

App-Level Keyboard Functions

ghostty_app_key

Sends a key event at the app level (for global keybindings).

ghostty_app_key_is_binding

Checks if a key is bound at the app level.

ghostty_app_has_global_keybinds

Checks if the app has any global keybindings.

ghostty_app_keyboard_changed

Notifies the app that the keyboard layout has changed.

Mouse Input

ghostty_surface_mouse_button

Sends a mouse button event to the surface.
surface
ghostty_surface_t
required
The surface.
state
ghostty_input_mouse_state_e
required
Button state (press or release).
button
ghostty_input_mouse_button_e
required
Which button was pressed.
mods
ghostty_input_mods_e
required
Modifier keys held.
Returns: true if the event was handled. Example:

ghostty_surface_mouse_pos

Sends a mouse position update to the surface.
surface
ghostty_surface_t
required
The surface.
x
double
required
X coordinate in pixels.
y
double
required
Y coordinate in pixels.
mods
ghostty_input_mods_e
required
Modifier keys held.

ghostty_surface_mouse_scroll

Sends a mouse scroll event to the surface.
surface
ghostty_surface_t
required
The surface.
delta_x
double
required
Horizontal scroll delta.
delta_y
double
required
Vertical scroll delta.
mods
ghostty_input_scroll_mods_t
required
Scroll modifiers (includes momentum phase information).

ghostty_surface_mouse_pressure

Sends mouse pressure information (for force touch).
surface
ghostty_surface_t
required
The surface.
stage
uint32_t
required
Pressure stage.
pressure
double
required
Pressure value (0.0-1.0).

ghostty_surface_mouse_captured

Checks if the terminal has captured the mouse (mouse reporting mode).
Returns: true if the mouse is captured for terminal mouse reporting.

Input Types

ghostty_input_key_s

Describes a keyboard event.
action
ghostty_input_action_e
The key action (press, release, repeat).
mods
ghostty_input_mods_e
Modifier keys held during the event.
consumed_mods
ghostty_input_mods_e
Modifiers consumed by the key translation.
keycode
uint32_t
The physical key code.
text
const char*
The text produced by the key (UTF-8, null-terminated).
unshifted_codepoint
uint32_t
The Unicode codepoint without shift modifier.
composing
bool
Whether this is part of an IME composition.

ghostty_input_action_e

ghostty_input_mods_e

Modifier key flags (can be combined with bitwise OR).
Example:

ghostty_input_mouse_state_e

ghostty_input_mouse_button_e

ghostty_input_mouse_momentum_e

Momentum/inertial scrolling phase.

ghostty_input_key_e

Physical key codes based on W3C UI Events KeyboardEvent code values.
See ghostty.h for the complete list of key codes.

ghostty_binding_flags_e

Flags for keybinding queries.

Complete Input Example

See Also