SDL3pp
A slim C++ wrapper for SDL3
|
SDL keyboard management. More...
Typedefs | |
using | SDL::KeyboardID = SDL_KeyboardID |
This is a unique ID for a keyboard for the time it is connected to the system, and is never reused for the lifetime of the application. | |
using | SDL::TextInputType = SDL_TextInputType |
Text input type. | |
using | SDL::Capitalization = SDL_Capitalization |
Auto capitalization type. | |
Functions | |
bool | SDL::HasKeyboard () |
Return whether a keyboard is currently connected. | |
KeyboardID * | SDL::GetKeyboards (int *count) |
Get a list of currently connected keyboards. | |
const char * | SDL::GetKeyboardNameForID (KeyboardID instance_id) |
Get the name of a keyboard. | |
WindowRef | SDL::GetKeyboardFocus () |
Query the window which currently has keyboard focus. | |
const bool * | SDL::GetKeyboardState (int *numkeys=nullptr) |
Get a snapshot of the current state of the keyboard. | |
void | SDL::ResetKeyboard () |
Clear the state of the keyboard. | |
Keymod | SDL::GetModState () |
Get the current key modifier state for the keyboard. | |
void | SDL::SetModState (Keymod modstate) |
Set the current key modifier state for the keyboard. | |
bool | SDL::HasScreenKeyboardSupport () |
Check whether the platform has screen keyboard support. | |
SDL::Keycode::Keycode (Scancode scancode, Keymod modstate=0, bool key_event=false) | |
Get the key code corresponding to the given scancode according to the current keyboard layout. | |
SDL::Keycode::Keycode (StringParam name) | |
Get a key code from a human-readable name. | |
Scancode | SDL::Keycode::GetScancode (Keymod *modstate) const |
Get the scancode corresponding to the given key code according to the current keyboard layout. | |
void | SDL::Scancode::SetName (StringParam name) |
Set a human-readable name for a scancode. | |
const char * | SDL::Scancode::GetName () const |
Get a human-readable name for a scancode. | |
SDL::Scancode::Scancode (StringParam name) | |
Get a scancode from a human-readable name. | |
const char * | SDL::Keycode::GetName () const |
Get a human-readable name for a key. | |
void | SDL::WindowBase::StartTextInput () |
Start accepting Unicode text input events in a window. | |
void | SDL::WindowBase::StartTextInput (PropertiesBase &props) |
Start accepting Unicode text input events in a window, with properties describing the input. | |
bool | SDL::WindowBase::IsTextInputActive () const |
Check whether or not Unicode text input events are enabled for a window. | |
void | SDL::WindowBase::StopTextInput () |
Stop receiving any text input events in a window. | |
void | SDL::WindowBase::ClearComposition () |
Dismiss the composition window/IME without disabling the subsystem. | |
void | SDL::WindowBase::SetTextInputArea (const SDL_Rect &rect, int cursor) |
Set the area used to type Unicode text input. | |
void | SDL::WindowBase::GetTextInputArea (Rect *rect, int *cursor) |
Get the area used to type Unicode text input. | |
bool | SDL::WindowBase::IsScreenKeyboardShown () const |
Check whether the screen keyboard is shown for given window. | |
Variables | |
constexpr TextInputType | SDL::TEXTINPUT_TYPE_TEXT |
The input is text. | |
constexpr TextInputType | SDL::TEXTINPUT_TYPE_TEXT_NAME |
The input is a person's name. | |
constexpr TextInputType | SDL::TEXTINPUT_TYPE_TEXT_EMAIL |
The input is an e-mail address. | |
constexpr TextInputType | SDL::TEXTINPUT_TYPE_TEXT_USERNAME |
The input is a username. | |
constexpr TextInputType | SDL::TEXTINPUT_TYPE_TEXT_PASSWORD_HIDDEN |
The input is a secure password that is hidden. | |
constexpr TextInputType | SDL::TEXTINPUT_TYPE_TEXT_PASSWORD_VISIBLE |
The input is a secure password that is visible. | |
constexpr TextInputType | SDL::TEXTINPUT_TYPE_NUMBER |
The input is a number. | |
constexpr TextInputType | SDL::TEXTINPUT_TYPE_NUMBER_PASSWORD_HIDDEN |
The input is a secure PIN that is hidden. | |
constexpr TextInputType | SDL::TEXTINPUT_TYPE_NUMBER_PASSWORD_VISIBLE |
The input is a secure PIN that is visible. | |
constexpr Capitalization | SDL::CAPITALIZE_NONE |
No auto-capitalization will be done. | |
constexpr Capitalization | SDL::CAPITALIZE_SENTENCES |
The first letter of sentences will be capitalized. | |
constexpr Capitalization | SDL::CAPITALIZE_WORDS |
The first letter of words will be capitalized. | |
constexpr Capitalization | SDL::CAPITALIZE_LETTERS |
All letters will be capitalized. | |
Please refer to the Best Keyboard Practices document for details on how best to accept keyboard input in various types of programs:
https://wiki.libsdl.org/SDL3/BestKeyboardPractices
using SDL::Capitalization = typedef SDL_Capitalization |
These are the valid values for prop::TextInput.CAPITALIZATION_NUMBER. Not every value is valid on every platform, but where a value isn't supported, a reasonable fallback will be used.
using SDL::KeyboardID = typedef SDL_KeyboardID |
If the keyboard is disconnected and reconnected, it will get a new ID.
The value 0 is an invalid ID.
using SDL::TextInputType = typedef SDL_TextInputType |
These are the valid values for prop::TextInput.TYPE_NUMBER. Not every value is valid on every platform, but where a value isn't supported, a reasonable fallback will be used.
|
inline |
|
inline |
|
inline |
This function returns "" if the keyboard doesn't have a name.
instance_id | the keyboard instance ID. |
|
inline |
Note that this will include any device or virtual driver that includes keyboard functionality, including some mice, KVM switches, motherboard power buttons, etc. You should wait for input from a device before you consider it actively in use.
count | a pointer filled in with the number of keyboards returned, may be nullptr. |
|
inline |
The pointer returned is a pointer to an internal SDL array. It will be valid for the whole lifetime of the application and should not be freed by the caller.
A array element with a value of true means that the key is pressed and a value of false means that it is not. Indexes into this array are obtained by using Scancode values.
Use PumpEvents() to update the state array.
This function gives you the current state after all events have been processed, so if a key or button has been pressed and released before you process events, then the pressed state will never show up in the GetKeyboardState() calls.
Note: This function doesn't take into account whether shift has been pressed or not.
numkeys | if non-nullptr, receives the length of the returned array. |
|
inline |
|
inline |
If the key doesn't have a name, this function returns an empty string ("").
Letters will be presented in their uppercase form, if applicable.
|
inline |
Warning: The returned name is by design not stable across platforms, e.g. the name for SCANCODE_LGUI
is "Left GUI" under Linux but "Left
Windows" under Microsoft Windows, and some scancodes like SCANCODE_NONUSBACKSLASH
don't have any name at all. There are even scancodes that share names, e.g. SCANCODE_RETURN
and SCANCODE_RETURN2
(both called "Return"). This function is therefore unsuitable for creating a stable cross-platform two-way mapping between strings and scancodes.
Note that there may be multiple scancode+modifier states that can generate this keycode, this will just return the first one found.
modstate | a pointer to the modifier state that would be used when the scancode generates this key, may be nullptr. |
|
inline |
This returns the values previously set by WindowBase.SetTextInputArea().
rect | a pointer to an Rect filled in with the text input area, may be nullptr. |
cursor | a pointer to the offset of the current cursor location relative to rect->x , may be nullptr. |
Error | on failure. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineexplicit |
If you want to get the keycode as it would be delivered in key events, including options specified in SDL_HINT_KEYCODE_OPTIONS, then you should pass key_event
as true. Otherwise this function simply translates the scancode based on the given modifier state.
scancode | the desired Scancode to query. |
modstate | the modifier state to use when translating the scancode to a keycode. |
key_event | true if the keycode will be used in key events. |
|
inlineexplicit |
name | the human-readable key name. |
SDLK_UNKNOWN
if the name wasn't recognized; call GetError() for more information.
|
inline |
This function will generate key up events for all pressed keys.
|
inline |
name | the human-readable scancode name. |
SCANCODE_UNKNOWN
if the name wasn't recognized; call GetError() for more information.
|
inline |
The inverse of GetModState(), SetModState() allows you to impose modifier key states on your application. Simply pass your desired modifier states into modstate
. This value may be a bitwise, OR'd combination of Keymod values.
This does not change the keyboard state, only the key modifier flags that SDL reports.
modstate | the desired Keymod for the keyboard. |
|
inline |
name | the name to use for the scancode, encoded as UTF-8. The string is not copied, so the pointer given to this function must stay valid while SDL is being used. |
Error | on failure. |
|
inline |
Native input methods may place a window with word suggestions near the cursor, without covering the text being entered.
rect | the Rect representing the text input area, in window coordinates, or nullptr to clear it. |
cursor | the offset of the current cursor location relative to rect->x , in window coordinates. |
Error | on failure. |
|
inline |
This function will enable text input (EVENT_TEXT_INPUT and EVENT_TEXT_EDITING events) in the specified window. Please use this function paired with WindowBase.StopTextInput().
Text input events are not received by default.
On some platforms using this function shows the screen keyboard and/or activates an IME, which can prevent some key press events from being passed through.
Error | on failure. |
|
inline |
This function will enable text input (EVENT_TEXT_INPUT and EVENT_TEXT_EDITING events) in the specified window. Please use this function paired with WindowBase.StopTextInput().
Text input events are not received by default.
On some platforms using this function shows the screen keyboard and/or activates an IME, which can prevent some key press events from being passed through.
These are the supported properties:
prop::TextInput.TYPE_NUMBER
- an TextInputType value that describes text being input, defaults to TEXTINPUT_TYPE_TEXT.prop::TextInput.CAPITALIZATION_NUMBER
- an Capitalization value that describes how text should be capitalized, defaults to CAPITALIZE_SENTENCES for normal text entry, CAPITALIZE_WORDS for TEXTINPUT_TYPE_TEXT_NAME, and CAPITALIZE_NONE for e-mail addresses, usernames, and passwords.prop::TextInput.AUTOCORRECT_BOOLEAN
- true to enable auto completion and auto correction, defaults to true.prop::TextInput.MULTILINE_BOOLEAN
- true if multiple lines of text are allowed. This defaults to true if SDL_HINT_RETURN_KEY_HIDES_IME is "0" or is not set, and defaults to false if SDL_HINT_RETURN_KEY_HIDES_IME is "1".On Android you can directly specify the input type:
prop::TextInput.ANDROID_INPUTTYPE_NUMBER
- the text input type to use, overriding other properties. This is documented at https://developer.android.com/reference/android/text/InputTypeprops | the properties to use. |
Error | on failure. |
|
inline |
If WindowBase.StartTextInput() showed the screen keyboard, this function will hide it.
Error | on failure. |
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |