Events, keyboard & mouseSDL 3.2

SDL_StartTextInput

Turns on text input for a window: SDL starts sending SDL_EVENT_TEXT_INPUT with typed characters.

Signature

bool SDL_StartTextInput(SDL_Window *window);

How it works

Key events are not text: "ã" on a Brazilian keyboard is two key presses, and Shift+2 is "@" on one layout and "\"" on another. Text input events carry the final UTF-8 string in e.text.text, after the system applied the layout, accents and input methods (Chinese, Japanese…).

In SDL3 text input is OFF by default (SDL2 had it on). Turn it on when a text field gets focus, and off again with SDL_StopTextInput. On phones this also shows the on-screen keyboard.

Parameters

windowSDL_Window *

The window that receives the text.

Return value

true on success, false on failure.

Example

example.cpp
1SDL_StartTextInput(window);          // name field focused
2// ...
3if (e.type == SDL_EVENT_TEXT_INPUT) playerName += e.text.text;   // UTF-8
4// ...
5SDL_StopTextInput(window);           // field closed
Official SDL wiki