SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
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
24
35using KeyboardID = SDL_KeyboardID;
36
48inline bool HasKeyboard() { return SDL_HasKeyboard(); }
49
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
169inline Keymod GetModState() { return SDL_GetModState(); }
170
189inline void SetModState(Keymod modstate) { SDL_SetModState(modstate); }
190
191inline Keycode::Keycode(Scancode scancode, Keymod modstate, bool key_event)
192 : m_keycode(SDL_GetKeyFromScancode(scancode, modstate, key_event))
193{
194}
195
197 : m_keycode(SDL_GetKeyFromName(name))
198{
199}
200
224 Keymod modstate,
225 bool key_event)
226{
227 return SDL_GetKeyFromScancode(scancode, modstate, key_event);
228}
229
249inline Scancode GetScancodeFromKey(Keycode key, Keymod* modstate = nullptr)
250{
251 return SDL_GetScancodeFromKey(key, modstate);
252}
253
254inline Scancode Keycode::GetScancode(Keymod* modstate) const
255{
256 return SDL_GetScancodeFromKey(m_keycode, modstate);
257}
258
274inline void SetScancodeName(Scancode scancode, StringParam name)
275{
276 CheckError(SDL_SetScancodeName(scancode, name));
277}
278
280{
281 CheckError(SDL_SetScancodeName(m_scancode, name));
282}
283
307inline const char* GetScancodeName(Scancode scancode)
308{
309 return SDL_GetScancodeName(scancode);
310}
311
312inline const char* Scancode::GetName() const
313{
314 return SDL_GetScancodeName(m_scancode);
315}
316
333{
334 return SDL_GetScancodeFromName(name);
335}
336
338 : m_scancode(SDL_GetScancodeFromName(name))
339{
340}
341
360inline const char* GetKeyName(Keycode key) { return SDL_GetKeyName(key); }
361
362inline const char* Keycode::GetName() const
363{
364 return SDL_GetKeyName(m_keycode);
365}
366
383{
384 return SDL_GetKeyFromName(name);
385}
386
412inline void StartTextInput(WindowRef window)
413{
414 CheckError(SDL_StartTextInput(window));
415}
416
418
430using TextInputType = SDL_TextInputType;
431
433 SDL_TEXTINPUT_TYPE_TEXT;
434
436 SDL_TEXTINPUT_TYPE_TEXT_NAME;
437
439 SDL_TEXTINPUT_TYPE_TEXT_EMAIL;
440
442 SDL_TEXTINPUT_TYPE_TEXT_USERNAME;
443
445 SDL_TEXTINPUT_TYPE_TEXT_PASSWORD_HIDDEN;
447
449 SDL_TEXTINPUT_TYPE_TEXT_PASSWORD_VISIBLE;
451
453 SDL_TEXTINPUT_TYPE_NUMBER;
454
456 SDL_TEXTINPUT_TYPE_NUMBER_PASSWORD_HIDDEN;
458
460 SDL_TEXTINPUT_TYPE_NUMBER_PASSWORD_VISIBLE;
462
474using Capitalization = SDL_Capitalization;
475
477 SDL_CAPITALIZE_NONE;
478
480 SDL_CAPITALIZE_SENTENCES;
482
484 SDL_CAPITALIZE_WORDS;
485
487 SDL_CAPITALIZE_LETTERS;
488
537{
538 CheckError(SDL_StartTextInputWithProperties(window, props));
539}
540
545
552
558constexpr auto TYPE_NUMBER = SDL_PROP_TEXTINPUT_TYPE_NUMBER;
559
565constexpr auto CAPITALIZATION_NUMBER = SDL_PROP_TEXTINPUT_CAPITALIZATION_NUMBER;
566
567constexpr auto AUTOCORRECT_BOOLEAN =
568 SDL_PROP_TEXTINPUT_AUTOCORRECT_BOOLEAN;
569
570constexpr auto MULTILINE_BOOLEAN =
571 SDL_PROP_TEXTINPUT_MULTILINE_BOOLEAN;
572
574 SDL_PROP_TEXTINPUT_ANDROID_INPUTTYPE_NUMBER;
576
577} // namespace prop::TextInput
578
591inline bool TextInputActive(WindowRef window)
592{
593 return SDL_TextInputActive(window);
594}
595
597{
598 return TextInputActive(get());
599}
600
616inline void StopTextInput(WindowRef window)
617{
618 CheckError(SDL_StopTextInput(window));
619}
620
622
636inline void ClearComposition(WindowRef window)
637{
638 CheckError(SDL_ClearComposition(window));
639}
640
642
663inline void SetTextInputArea(WindowRef window, const RectRaw& rect, int cursor)
664{
665 CheckError(SDL_SetTextInputArea(window, &rect, cursor));
666}
667
668inline void WindowBase::SetTextInputArea(const RectRaw& rect, int cursor)
669{
670 SDL::SetTextInputArea(get(), rect, cursor);
671}
672
691inline void GetTextInputArea(WindowRef window, RectRaw* rect, int* cursor)
692{
693 CheckError(SDL_GetTextInputArea(window, rect, cursor));
694}
695
696inline void WindowBase::GetTextInputArea(RectRaw* rect, int* cursor) const
697{
698 SDL::GetTextInputArea(get(), rect, cursor);
699}
700
715{
716 return SDL_HasScreenKeyboardSupport();
717}
718
732{
733 return SDL_ScreenKeyboardShown(window);
734}
735
737{
738 return ScreenKeyboardShown(get());
739}
740
742
743} // namespace SDL
744
745#endif /* SDL3PP_KEYBOARD_H_ */
The SDL virtual key representation.
Definition SDL3pp_keycode.h:120
constexpr Keycode(KeycodeRaw keycode={}) noexcept
Wraps Keycode.
Definition SDL3pp_keycode.h:129
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
The SDL keyboard scancode representation.
Definition SDL3pp_scancode.h:46
constexpr Scancode(ScancodeRaw scancode={}) noexcept
Wraps Scancode.
Definition SDL3pp_scancode.h:55
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:199
constexpr TextInputType TEXTINPUT_TYPE_NUMBER_PASSWORD_HIDDEN
The input is a secure PIN that is hidden.
Definition SDL3pp_keyboard.h:455
void SetName(StringParam name)
Set a human-readable name for a scancode.
Definition SDL3pp_keyboard.h:279
void StopTextInput(WindowRef window)
Stop receiving any text input events in a window.
Definition SDL3pp_keyboard.h:616
const char * GetName() const
Get a human-readable name for a key.
Definition SDL3pp_keyboard.h:362
Keycode GetKeyFromScancode(Scancode scancode, Keymod modstate, bool key_event)
Get the key code corresponding to the given scancode according to the current keyboard layout.
Definition SDL3pp_keyboard.h:223
SDL_Capitalization Capitalization
Auto capitalization type.
Definition SDL3pp_keyboard.h:474
void ResetKeyboard()
Clear the state of the keyboard.
Definition SDL3pp_keyboard.h:155
void StopTextInput()
Stop receiving any text input events in a window.
Definition SDL3pp_keyboard.h:621
void SetTextInputArea(WindowRef window, const RectRaw &rect, int cursor)
Set the area used to type Unicode text input.
Definition SDL3pp_keyboard.h:663
void StartTextInput(WindowRef window)
Start accepting Unicode text input events in a window.
Definition SDL3pp_keyboard.h:412
bool HasKeyboard()
Return whether a keyboard is currently connected.
Definition SDL3pp_keyboard.h:48
void SetModState(Keymod modstate)
Set the current key modifier state for the keyboard.
Definition SDL3pp_keyboard.h:189
constexpr TextInputType TEXTINPUT_TYPE_TEXT_NAME
The input is a person's name.
Definition SDL3pp_keyboard.h:435
Keymod GetModState()
Get the current key modifier state for the keyboard.
Definition SDL3pp_keyboard.h:169
bool IsScreenKeyboardShown() const
Check whether the screen keyboard is shown for given window.
Definition SDL3pp_keyboard.h:736
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
const char * GetKeyName(Keycode key)
Get a human-readable name for a key.
Definition SDL3pp_keyboard.h:360
Scancode GetScancodeFromKey(Keycode key, Keymod *modstate=nullptr)
Get the scancode corresponding to the given key code according to the current keyboard layout.
Definition SDL3pp_keyboard.h:249
constexpr TextInputType TEXTINPUT_TYPE_TEXT_PASSWORD_HIDDEN
The input is a secure password that is hidden.
Definition SDL3pp_keyboard.h:444
void SetTextInputArea(const RectRaw &rect, int cursor)
Set the area used to type Unicode text input.
Definition SDL3pp_keyboard.h:668
constexpr TextInputType TEXTINPUT_TYPE_TEXT_EMAIL
The input is an e-mail address.
Definition SDL3pp_keyboard.h:438
constexpr Capitalization CAPITALIZE_SENTENCES
The first letter of sentences will be capitalized.
Definition SDL3pp_keyboard.h:479
void SetScancodeName(Scancode scancode, StringParam name)
Set a human-readable name for a scancode.
Definition SDL3pp_keyboard.h:274
void StartTextInputWithProperties(PropertiesRef props)
Start accepting Unicode text input events in a window, with properties describing the input.
Definition SDL3pp_keyboard.h:541
OwnArray< KeyboardID > GetKeyboards()
Get a list of currently connected keyboards.
Definition SDL3pp_keyboard.h:69
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:35
Scancode GetScancodeFromName(StringParam name)
Get a scancode from a human-readable name.
Definition SDL3pp_keyboard.h:332
constexpr TextInputType TEXTINPUT_TYPE_TEXT_USERNAME
The input is a username.
Definition SDL3pp_keyboard.h:441
bool IsTextInputActive() const
Check whether or not Unicode text input events are enabled for a window.
Definition SDL3pp_keyboard.h:596
Keycode GetKeyFromName(StringParam name)
Get a key code from a human-readable name.
Definition SDL3pp_keyboard.h:382
constexpr TextInputType TEXTINPUT_TYPE_TEXT
The input is text.
Definition SDL3pp_keyboard.h:432
constexpr Capitalization CAPITALIZE_NONE
No auto-capitalization will be done.
Definition SDL3pp_keyboard.h:476
void ClearComposition(WindowRef window)
Dismiss the composition window/IME without disabling the subsystem.
Definition SDL3pp_keyboard.h:636
bool ScreenKeyboardShown(WindowRef window)
Check whether the screen keyboard is shown for given window.
Definition SDL3pp_keyboard.h:731
Scancode GetScancode(Keymod *modstate=nullptr) const
Get the scancode corresponding to the given key code according to the current keyboard layout.
Definition SDL3pp_keyboard.h:254
bool TextInputActive(WindowRef window)
Check whether or not Unicode text input events are enabled for a window.
Definition SDL3pp_keyboard.h:591
void GetTextInputArea(WindowRef window, RectRaw *rect, int *cursor)
Get the area used to type Unicode text input.
Definition SDL3pp_keyboard.h:691
const char * GetName() const
Get a human-readable name for a scancode.
Definition SDL3pp_keyboard.h:312
constexpr Capitalization CAPITALIZE_WORDS
The first letter of words will be capitalized.
Definition SDL3pp_keyboard.h:483
void StartTextInput()
Start accepting Unicode text input events in a window.
Definition SDL3pp_keyboard.h:417
constexpr TextInputType TEXTINPUT_TYPE_NUMBER
The input is a number.
Definition SDL3pp_keyboard.h:452
void GetTextInputArea(RectRaw *rect, int *cursor) const
Get the area used to type Unicode text input.
Definition SDL3pp_keyboard.h:696
constexpr TextInputType TEXTINPUT_TYPE_TEXT_PASSWORD_VISIBLE
The input is a secure password that is visible.
Definition SDL3pp_keyboard.h:448
void ClearComposition()
Dismiss the composition window/IME without disabling the subsystem.
Definition SDL3pp_keyboard.h:641
constexpr TextInputType TEXTINPUT_TYPE_NUMBER_PASSWORD_VISIBLE
The input is a secure PIN that is visible.
Definition SDL3pp_keyboard.h:459
void StartTextInputWithProperties(WindowRef window, PropertiesRef props)
Start accepting Unicode text input events in a window, with properties describing the input.
Definition SDL3pp_keyboard.h:536
SDL_TextInputType TextInputType
Text input type.
Definition SDL3pp_keyboard.h:430
constexpr Capitalization CAPITALIZE_LETTERS
All letters will be capitalized.
Definition SDL3pp_keyboard.h:486
bool HasScreenKeyboardSupport()
Check whether the platform has screen keyboard support.
Definition SDL3pp_keyboard.h:714
const char * GetScancodeName(Scancode scancode)
Get a human-readable name for a scancode.
Definition SDL3pp_keyboard.h:307
std::span< const bool > GetKeyboardState()
Get a snapshot of the current state of the keyboard.
Definition SDL3pp_keyboard.h:137
Uint16 Keymod
Valid key modifiers (possibly OR'd together).
Definition SDL3pp_keycode.h:34
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:53
SDL_Rect RectRaw
Alias to raw representation for Rect.
Definition SDL3pp_rect.h:34
ResourceRefT< WindowBase > WindowRef
Reference for Window.
Definition SDL3pp_video.h:57
Properties for text input to be used on StartTextInputWithProperties.
Definition SDL3pp_keyboard.h:551
constexpr auto AUTOCORRECT_BOOLEAN
Autocorrect enabled.
Definition SDL3pp_keyboard.h:567
constexpr auto ANDROID_INPUTTYPE_NUMBER
Number for android inputtype.
Definition SDL3pp_keyboard.h:573
constexpr auto MULTILINE_BOOLEAN
Multiline enabled.
Definition SDL3pp_keyboard.h:570
constexpr auto CAPITALIZATION_NUMBER
The auto-capitalization type to be used.
Definition SDL3pp_keyboard.h:565
constexpr auto TYPE_NUMBER
The type of text input to be used.
Definition SDL3pp_keyboard.h:558
Main include header for the SDL3pp library.