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.ghostty_surface_t
required
The surface to send the key event to.
ghostty_input_key_s
required
The key event data.
true if the key was handled, false otherwise.
Example:
ghostty_surface_key_is_binding
Checks if a key is bound to an action.ghostty_surface_t
required
The surface to check.
ghostty_input_key_s
required
The key to check.
ghostty_binding_flags_e*
Optional pointer to receive binding flags.
true if the key is bound to an action.
ghostty_surface_text
Sends text directly to the surface (for IME or pasted text).ghostty_surface_t
required
The surface to send text to.
const char*
required
The text to send.
uintptr_t
required
Length of the text in bytes.
ghostty_surface_preedit
Sends IME pre-edit text to the surface.ghostty_surface_t
required
The surface.
const char*
required
The pre-edit text.
uintptr_t
required
Length of the text.
ghostty_surface_ime_point
Gets the screen coordinates for IME candidate window positioning.ghostty_surface_t
required
The surface.
double*
required
Pointer to store X coordinate.
double*
required
Pointer to store Y coordinate.
double*
required
Pointer to store width.
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.ghostty_surface_t
required
The surface.
ghostty_input_mouse_state_e
required
Button state (press or release).
ghostty_input_mouse_button_e
required
Which button was pressed.
ghostty_input_mods_e
required
Modifier keys held.
true if the event was handled.
Example:
ghostty_surface_mouse_pos
Sends a mouse position update to the surface.ghostty_surface_t
required
The surface.
double
required
X coordinate in pixels.
double
required
Y coordinate in pixels.
ghostty_input_mods_e
required
Modifier keys held.
ghostty_surface_mouse_scroll
Sends a mouse scroll event to the surface.ghostty_surface_t
required
The surface.
double
required
Horizontal scroll delta.
double
required
Vertical scroll delta.
ghostty_input_scroll_mods_t
required
Scroll modifiers (includes momentum phase information).
ghostty_surface_mouse_pressure
Sends mouse pressure information (for force touch).ghostty_surface_t
required
The surface.
uint32_t
required
Pressure stage.
double
required
Pressure value (0.0-1.0).
ghostty_surface_mouse_captured
Checks if the terminal has captured the mouse (mouse reporting mode).true if the mouse is captured for terminal mouse reporting.
Input Types
ghostty_input_key_s
Describes a keyboard event.ghostty_input_action_e
The key action (press, release, repeat).
ghostty_input_mods_e
Modifier keys held during the event.
ghostty_input_mods_e
Modifiers consumed by the key translation.
uint32_t
The physical key code.
const char*
The text produced by the key (UTF-8, null-terminated).
uint32_t
The Unicode codepoint without shift modifier.
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).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.ghostty.h for the complete list of key codes.
ghostty_binding_flags_e
Flags for keybinding queries.Complete Input Example
See Also
- Core Types - Input-related types
- Rendering - Focus and display updates