SDL3pp
A slim C++ wrapper for SDL3
All Classes Namespaces Functions Variables Typedefs Modules Pages Concepts
SDL3pp_keyboard.h
1#ifndef SDL3PP_KEYBOARD_H_
2#define SDL3PP_KEYBOARD_H_
3
4#include <SDL3/SDL_keyboard.h>
5#include "SDL3pp_keycode.h"
6#include "SDL3pp_scancode.h"
7#include "SDL3pp_stdinc.h"
8#include "SDL3pp_video.h"
9
10namespace SDL {
11
36using KeyboardID = SDL_KeyboardID;
37
49inline bool HasKeyboard() { return SDL_HasKeyboard(); }
50
70{
71 int count;
72 auto data = CheckError(SDL_GetKeyboards(&count));
73 return OwnArray<KeyboardID>{data, size_t(count)};
74}
75
91inline const char* GetKeyboardNameForID(KeyboardID instance_id)
92{
93 return SDL_GetKeyboardNameForID(instance_id);
94}
95
105inline WindowRef GetKeyboardFocus() { return SDL_GetKeyboardFocus(); }
106
137inline std::span<const bool> GetKeyboardState()
138{
139 int count;
140 auto data = SDL_GetKeyboardState(&count);
141 return std::span{data, size_t(count)};
142}
143
155inline void ResetKeyboard() { SDL_ResetKeyboard(); }
156
170inline Keymod GetModState() { return SDL_GetModState(); }
171
191inline void SetModState(Keymod modstate) { SDL_SetModState(modstate); }
192
215inline Keycode::Keycode(Scancode scancode, Keymod modstate, bool key_event)
216 : Keycode(SDL_GetKeyFromScancode(scancode, modstate, key_event))
217{
218}
219
236 : Keycode(SDL_GetKeyFromName(name))
237{
238}
239
258inline Scancode Keycode::GetScancode(Keymod* modstate) const
259{
260 return SDL_GetScancodeFromKey(m_keycode, modstate);
261}
262
278{
279 CheckError(SDL_SetScancodeName(m_scancode, name));
280}
281
305inline const char* Scancode::GetName() const
306{
307 return SDL_GetScancodeName(m_scancode);
308}
309
326 : Scancode(SDL_GetScancodeFromName(name))
327{
328}
329
347inline const char* Keycode::GetName() const
348{
349 return SDL_GetKeyName(m_keycode);
350}
351
377{
378 return CheckError(SDL_StartTextInput(get()));
379}
380
430{
431 CheckError(SDL_StartTextInputWithProperties(get(), props.get()));
432}
433
445using TextInputType = SDL_TextInputType;
446
448 SDL_TEXTINPUT_TYPE_TEXT;
449
451 SDL_TEXTINPUT_TYPE_TEXT_NAME;
452
454 SDL_TEXTINPUT_TYPE_TEXT_EMAIL;
455
457 SDL_TEXTINPUT_TYPE_TEXT_USERNAME;
458
460 SDL_TEXTINPUT_TYPE_TEXT_PASSWORD_HIDDEN;
462
464 SDL_TEXTINPUT_TYPE_TEXT_PASSWORD_VISIBLE;
466
468 SDL_TEXTINPUT_TYPE_NUMBER;
469
471 SDL_TEXTINPUT_TYPE_NUMBER_PASSWORD_HIDDEN;
473
475 SDL_TEXTINPUT_TYPE_NUMBER_PASSWORD_VISIBLE;
477
489using Capitalization = SDL_Capitalization;
490
492 SDL_CAPITALIZE_NONE;
493
495 SDL_CAPITALIZE_SENTENCES;
497
499 SDL_CAPITALIZE_WORDS;
500
502 SDL_CAPITALIZE_LETTERS;
503
504namespace prop::TextInput {
505
506constexpr auto TYPE_NUMBER = SDL_PROP_TEXTINPUT_TYPE_NUMBER;
507
508constexpr auto CAPITALIZATION_NUMBER = SDL_PROP_TEXTINPUT_CAPITALIZATION_NUMBER;
509
510constexpr auto AUTOCORRECT_BOOLEAN = SDL_PROP_TEXTINPUT_AUTOCORRECT_BOOLEAN;
511
512constexpr auto MULTILINE_BOOLEAN = SDL_PROP_TEXTINPUT_MULTILINE_BOOLEAN;
513
514constexpr auto ANDROID_INPUTTYPE_NUMBER =
515 SDL_PROP_TEXTINPUT_ANDROID_INPUTTYPE_NUMBER;
516
517} // namespace prop::TextInput
518
531{
532 return SDL_TextInputActive(get());
533}
534
549inline void WindowRef::StopTextInput() { CheckError(SDL_StopTextInput(get())); }
550
564{
565 CheckError(SDL_ClearComposition(get()));
566}
567
587inline void WindowRef::SetTextInputArea(const SDL_Rect& rect, int cursor)
588{
589 CheckError(SDL_SetTextInputArea(get(), &rect, cursor));
590}
591
609inline void WindowRef::GetTextInputArea(Rect* rect, int* cursor)
610{
611 CheckError(SDL_GetTextInputArea(get(), rect, cursor));
612}
613
628{
629 return SDL_HasScreenKeyboardSupport();
630}
631
644{
645 return SDL_ScreenKeyboardShown(get());
646}
647
649} // namespace SDL
650
651#endif /* SDL3PP_KEYBOARD_H_ */
The SDL virtual key representation.
Definition SDL3pp_keycode.h:113
constexpr Keycode(SDL_Keycode keycode={})
Wraps Keycode.
Definition SDL3pp_keycode.h:122
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:43
constexpr SDL_Window * get() const
Return contained resource;.
Definition SDL3pp_resource.h:76
The SDL keyboard scancode representation.
Definition SDL3pp_scancode.h:41
constexpr Scancode(SDL_Scancode scancode={})
Wraps Scancode.
Definition SDL3pp_scancode.h:50
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
constexpr TextInputType TEXTINPUT_TYPE_NUMBER_PASSWORD_HIDDEN
The input is a secure PIN that is hidden.
Definition SDL3pp_keyboard.h:470
void SetName(StringParam name)
Set a human-readable name for a scancode.
Definition SDL3pp_keyboard.h:277
const char * GetName() const
Get a human-readable name for a key.
Definition SDL3pp_keyboard.h:347
SDL_KeyboardID KeyboardID
This is a unique ID for a keyboard for the time it is connected to the system, and is never reused fo...
Definition SDL3pp_keyboard.h:36
void ResetKeyboard()
Clear the state of the keyboard.
Definition SDL3pp_keyboard.h:155
bool IsScreenKeyboardShown() const
Check whether the screen keyboard is shown for given window.
Definition SDL3pp_keyboard.h:643
bool HasKeyboard()
Return whether a keyboard is currently connected.
Definition SDL3pp_keyboard.h:49
void SetModState(Keymod modstate)
Set the current key modifier state for the keyboard.
Definition SDL3pp_keyboard.h:191
void StopTextInput()
Stop receiving any text input events in a window.
Definition SDL3pp_keyboard.h:549
constexpr TextInputType TEXTINPUT_TYPE_TEXT_NAME
The input is a person's name.
Definition SDL3pp_keyboard.h:450
Keymod GetModState()
Get the current key modifier state for the keyboard.
Definition SDL3pp_keyboard.h:170
const char * GetKeyboardNameForID(KeyboardID instance_id)
Get the name of a keyboard.
Definition SDL3pp_keyboard.h:91
WindowRef GetKeyboardFocus()
Query the window which currently has keyboard focus.
Definition SDL3pp_keyboard.h:105
constexpr TextInputType TEXTINPUT_TYPE_TEXT_PASSWORD_HIDDEN
The input is a secure password that is hidden.
Definition SDL3pp_keyboard.h:459
constexpr TextInputType TEXTINPUT_TYPE_TEXT_EMAIL
The input is an e-mail address.
Definition SDL3pp_keyboard.h:453
constexpr Capitalization CAPITALIZE_SENTENCES
The first letter of sentences will be capitalized.
Definition SDL3pp_keyboard.h:494
void StartTextInput()
Start accepting Unicode text input events in a window.
Definition SDL3pp_keyboard.h:376
OwnArray< KeyboardID > GetKeyboards()
Get a list of currently connected keyboards.
Definition SDL3pp_keyboard.h:69
constexpr TextInputType TEXTINPUT_TYPE_TEXT_USERNAME
The input is a username.
Definition SDL3pp_keyboard.h:456
SDL_TextInputType TextInputType
Text input type.
Definition SDL3pp_keyboard.h:445
Scancode GetScancode(Keymod *modstate) const
Get the scancode corresponding to the given key code according to the current keyboard layout.
Definition SDL3pp_keyboard.h:258
void ClearComposition()
Dismiss the composition window/IME without disabling the subsystem.
Definition SDL3pp_keyboard.h:563
constexpr TextInputType TEXTINPUT_TYPE_TEXT
The input is text.
Definition SDL3pp_keyboard.h:447
void SetTextInputArea(const SDL_Rect &rect, int cursor)
Set the area used to type Unicode text input.
Definition SDL3pp_keyboard.h:587
constexpr Capitalization CAPITALIZE_NONE
No auto-capitalization will be done.
Definition SDL3pp_keyboard.h:491
SDL_Capitalization Capitalization
Auto capitalization type.
Definition SDL3pp_keyboard.h:489
void GetTextInputArea(Rect *rect, int *cursor)
Get the area used to type Unicode text input.
Definition SDL3pp_keyboard.h:609
const char * GetName() const
Get a human-readable name for a scancode.
Definition SDL3pp_keyboard.h:305
constexpr Capitalization CAPITALIZE_WORDS
The first letter of words will be capitalized.
Definition SDL3pp_keyboard.h:498
constexpr TextInputType TEXTINPUT_TYPE_NUMBER
The input is a number.
Definition SDL3pp_keyboard.h:467
constexpr TextInputType TEXTINPUT_TYPE_TEXT_PASSWORD_VISIBLE
The input is a secure password that is visible.
Definition SDL3pp_keyboard.h:463
constexpr TextInputType TEXTINPUT_TYPE_NUMBER_PASSWORD_VISIBLE
The input is a secure PIN that is visible.
Definition SDL3pp_keyboard.h:474
constexpr Capitalization CAPITALIZE_LETTERS
All letters will be capitalized.
Definition SDL3pp_keyboard.h:501
bool HasScreenKeyboardSupport()
Check whether the platform has screen keyboard support.
Definition SDL3pp_keyboard.h:627
std::span< const bool > GetKeyboardState()
Get a snapshot of the current state of the keyboard.
Definition SDL3pp_keyboard.h:137
bool IsTextInputActive() const
Check whether or not Unicode text input events are enabled for a window.
Definition SDL3pp_keyboard.h:530
Uint16 Keymod
Valid key modifiers (possibly OR'd together).
Definition SDL3pp_keycode.h:29
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
SDL properties ID.
Definition SDL3pp_properties.h:209
A rectangle, with the origin at the upper left (using integers).
Definition SDL3pp_rect.h:833
Represents a handle to a window.
Definition SDL3pp_video.h:860