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.The surface to send the key event to.
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.The surface to check.
The key to check.
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).The surface to send text to.
The text to send.
Length of the text in bytes.
ghostty_surface_preedit
Sends IME pre-edit text to the surface.The surface.
The pre-edit text.
Length of the text.
ghostty_surface_ime_point
Gets the screen coordinates for IME candidate window positioning.The surface.
Pointer to store X coordinate.
Pointer to store Y coordinate.
Pointer to store width.
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.The surface.
Button state (press or release).
Which button was pressed.
Modifier keys held.
true if the event was handled.
Example:
ghostty_surface_mouse_pos
Sends a mouse position update to the surface.The surface.
X coordinate in pixels.
Y coordinate in pixels.
Modifier keys held.
ghostty_surface_mouse_scroll
Sends a mouse scroll event to the surface.The surface.
Horizontal scroll delta.
Vertical scroll delta.
Scroll modifiers (includes momentum phase information).
ghostty_surface_mouse_pressure
Sends mouse pressure information (for force touch).The surface.
Pressure stage.
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.The key action (press, release, repeat).
Modifier keys held during the event.
Modifiers consumed by the key translation.
The physical key code.
The text produced by the key (UTF-8, null-terminated).
The Unicode codepoint without shift modifier.
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