// // Generated by Brutal.Sdl.Generate; do not edit by hand. #nullable enable namespace Brutal.SdlApi { public static unsafe partial class Sdl { public static unsafe partial class Keyboard { /// /// Return whether a keyboard is currently connected. /// /// true if a keyboard is connected, false otherwise. /// /// This function should only be called on the main thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static bool HasKeyboard() => PInvoke.HasKeyboard() != 0; /// /// Ergonomic wrapper over SDL_GetKeyboards. /// /// The SDL call failed; the message carries the /// SDL_GetError text. /// /// SDL returns a freshly SDL_malloc'd buffer for this call; the returned array is a managed copy, /// and the native buffer is freed with SDL_free before this method returns. /// public static uint[] GetKeyboards() { int count; var ptr = PInvoke.GetKeyboards(&count); if (ptr is null) throw SdlException.FromError("SDL_GetKeyboards failed"); try { return new ReadOnlySpan(ptr, count).ToArray(); } finally { PInvoke.Free(ptr); } } /// /// Get the name of a keyboard. /// /// the keyboard instance ID. /// /// the name of the selected keyboard or NULL on failure; call /// SDL_GetError() for more information. /// /// /// /// This function returns "" if the keyboard doesn't have a name. /// /// /// /// This function should only be called on the main thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static string? GetKeyboardNameForID(uint instance_id) => PInvoke.GetKeyboardNameForID(instance_id); /// /// Ergonomic wrapper over SDL_GetKeyboardFocus. /// /// /// Borrowed handle: the returned handle is owned by SDL (or by another object) and must not be /// disposed. Do not call on it; doing so would free a resource /// this call does not own. A null handle is returned on failure. /// public static SdlWindow GetKeyboardFocus() => PInvoke.GetKeyboardFocus(); /// /// Ergonomic wrapper over SDL_GetKeyboardState. /// /// /// The returned array is a managed copy of SDL's own internal buffer, which SDL owns for the lifetime of /// the process; nothing here is freed. /// public static bool[] GetKeyboardState() { int numkeys; var ptr = PInvoke.GetKeyboardState(&numkeys); if (ptr is null) return []; var result = new bool[numkeys]; for (var i = 0; i < numkeys; i++) result[i] = ptr[i] != 0; return result; } /// /// Clear the state of the keyboard. /// /// /// /// This function will generate key up events for all pressed keys. /// /// /// /// This function should only be called on the main thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static void ResetKeyboard() => PInvoke.ResetKeyboard(); /// /// Get the current key modifier state for the keyboard. /// /// an OR'd combination of the modifier keys for the keyboard. /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static ushort GetModState() => PInvoke.GetModState(); /// /// Set the current key modifier state for the keyboard. /// /// the desired SDL_Keymod for the keyboard. /// /// /// The inverse of SDL_GetModState(), SDL_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 /// SDL_Keymod values. /// /// /// This does not change the keyboard state, only the key modifier flags that /// SDL reports. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static void SetModState(ushort modstate) => PInvoke.SetModState(modstate); /// /// Get the key code corresponding to the given scancode according to the /// current keyboard layout. /// /// the desired SDL_Scancode to query. /// /// the modifier state to use when translating the scancode to /// a keycode. /// /// true if the keycode will be used in key events. /// the SDL_Keycode that corresponds to the given SDL_Scancode. /// /// /// 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. /// /// /// /// This function is not thread safe. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static SdlKeycode GetKeyFromScancode(SdlScancode scancode, ushort modstate, bool key_event) => PInvoke.GetKeyFromScancode(scancode, modstate, key_event ? (byte)1 : (byte)0); /// /// Get the scancode corresponding to the given key code according to the /// current keyboard layout. /// /// the desired SDL_Keycode to query. /// /// a pointer to the modifier state that would be used when the /// scancode generates this key, may be NULL. /// /// the SDL_Scancode that corresponds to the given SDL_Keycode. /// /// /// Note that there may be multiple scancode+modifier states that can generate /// this keycode, this will just return the first one found. /// /// /// /// This function is not thread safe. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static SdlScancode GetScancodeFromKey(SdlKeycode key, ushort* modstate) => PInvoke.GetScancodeFromKey(key, modstate); /// /// Get a human-readable name for a scancode. /// /// the desired SDL_Scancode to query. /// /// a pointer to the name for the scancode. If the scancode doesn't /// have a name this function returns an empty string (""). /// /// /// /// Warning: The returned name is by design not stable across platforms, /// e.g. the name for SDL_SCANCODE_LGUI is "Left GUI" under Linux but "Left /// Windows" under Microsoft Windows, and some scancodes like /// SDL_SCANCODE_NONUSBACKSLASH don't have any name at all. There are even /// scancodes that share names, e.g. SDL_SCANCODE_RETURN and /// SDL_SCANCODE_RETURN2 (both called "Return"). This function is therefore /// unsuitable for creating a stable cross-platform two-way mapping between /// strings and scancodes. /// /// /// /// This function is not thread safe. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static string? GetScancodeName(SdlScancode scancode) => PInvoke.GetScancodeName(scancode); /// /// Get a scancode from a human-readable name. /// /// the human-readable scancode name. /// /// the SDL_Scancode, or SDL_SCANCODE_UNKNOWN if the name wasn't /// recognized; call SDL_GetError() for more information. /// /// /// This function is not thread safe. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// public static SdlScancode GetScancodeFromName(string name) => PInvoke.GetScancodeFromName(name); /// /// Get a human-readable name for a key. /// /// the desired SDL_Keycode to query. /// a UTF-8 encoded string of the key name. /// /// /// If the key doesn't have a name, this function returns an empty string (""). /// /// /// Letters will be presented in their uppercase form, if applicable. /// /// /// /// This function is not thread safe. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// public static string? GetKeyName(SdlKeycode key) => PInvoke.GetKeyName(key); /// /// Get a key code from a human-readable name. /// /// the human-readable key name. /// /// key code, or SDLK_UNKNOWN if the name wasn't recognized; call /// SDL_GetError() for more information. /// /// /// This function is not thread safe. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// public static SdlKeycode GetKeyFromName(string name) => PInvoke.GetKeyFromName(name); /// /// Start accepting Unicode text input events in a window. /// /// the window to enable text input. /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// /// This function will enable text input (SDL_EVENT_TEXT_INPUT and /// SDL_EVENT_TEXT_EDITING events) in the specified window. Please use this /// function paired with SDL_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. /// /// /// /// This function should only be called on the main thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// /// public static bool StartTextInput(SdlWindow window) => PInvoke.StartTextInput(window) != 0; /// /// Start accepting Unicode text input events in a window, with properties /// describing the input. /// /// the window to enable text input. /// the properties to use. /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// /// This function will enable text input (SDL_EVENT_TEXT_INPUT and /// SDL_EVENT_TEXT_EDITING events) in the specified window. Please use this /// function paired with SDL_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: /// /// /// - SDL_PROP_TEXTINPUT_TYPE_NUMBER - an SDL_TextInputType value that /// describes text being input, defaults to SDL_TEXTINPUT_TYPE_TEXT. /// - SDL_PROP_TEXTINPUT_CAPITALIZATION_NUMBER - an SDL_Capitalization value /// that describes how text should be capitalized, defaults to /// SDL_CAPITALIZE_SENTENCES for normal text entry, SDL_CAPITALIZE_WORDS for /// SDL_TEXTINPUT_TYPE_TEXT_NAME, and SDL_CAPITALIZE_NONE for e-mail /// addresses, usernames, and passwords. /// - SDL_PROP_TEXTINPUT_AUTOCORRECT_BOOLEAN - true to enable auto completion /// and auto correction, defaults to true. /// - SDL_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: /// /// /// - SDL_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/InputType /// /// /// /// This function should only be called on the main thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// /// public static bool StartTextInputWithProperties(SdlWindow window, uint props) => PInvoke.StartTextInputWithProperties(window, props) != 0; /// /// Check whether or not Unicode text input events are enabled for a window. /// /// the window to check. /// true if text input events are enabled else false. /// /// This function should only be called on the main thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static bool TextInputActive(SdlWindow window) => PInvoke.TextInputActive(window) != 0; /// /// Stop receiving any text input events in a window. /// /// the window to disable text input. /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// /// If SDL_StartTextInput() showed the screen keyboard, this function will hide /// it. /// /// /// /// This function should only be called on the main thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static bool StopTextInput(SdlWindow window) => PInvoke.StopTextInput(window) != 0; /// /// Dismiss the composition window/IME without disabling the subsystem. /// /// the window to affect. /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// This function should only be called on the main thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static bool ClearComposition(SdlWindow window) => PInvoke.ClearComposition(window) != 0; /// /// Set the area used to type Unicode text input. /// /// the window for which to set the text input area. /// /// the SDL_Rect representing the text input area, in window /// coordinates, or NULL to clear it. /// /// /// the offset of the current cursor location relative to /// rect->x, in window coordinates. /// /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// /// Native input methods may place a window with word suggestions near the /// cursor, without covering the text being entered. /// /// /// /// This function should only be called on the main thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static bool SetTextInputArea(SdlWindow window, SdlRect* rect, int cursor) => PInvoke.SetTextInputArea(window, rect, cursor) != 0; /// /// Get the area used to type Unicode text input. /// /// the window for which to query the text input area. /// /// a pointer to an SDL_Rect filled in with the text input area, /// may be NULL. /// /// /// a pointer to the offset of the current cursor location /// relative to rect->x, may be NULL. /// /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// /// This returns the values previously set by SDL_SetTextInputArea(). /// /// /// /// This function should only be called on the main thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static bool GetTextInputArea(SdlWindow window, SdlRect* rect, out int cursor) { cursor = default; fixed (int* cursorPtr = &cursor) { return PInvoke.GetTextInputArea(window, rect, cursorPtr) != 0; } } /// /// Check whether the platform has screen keyboard support. /// /// /// true if the platform has some screen keyboard support or false if /// not. /// /// /// This function should only be called on the main thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static bool HasScreenKeyboardSupport() => PInvoke.HasScreenKeyboardSupport() != 0; /// /// Check whether the screen keyboard is shown for given window. /// /// the window for which screen keyboard should be queried. /// true if screen keyboard is shown or false if not. /// /// This function should only be called on the main thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static bool ScreenKeyboardShown(SdlWindow window) => PInvoke.ScreenKeyboardShown(window) != 0; } } }