SDL_keyboard_c.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_internal.h"
  19. #ifndef SDL_keyboard_c_h_
  20. #define SDL_keyboard_c_h_
  21. #include "SDL_keymap_c.h"
  22. // Keyboard events not associated with a specific input device
  23. #define SDL_GLOBAL_KEYBOARD_ID 0
  24. // The default keyboard input device, for platforms that don't have multiple keyboards
  25. #define SDL_DEFAULT_KEYBOARD_ID 1
  26. // Initialize the keyboard subsystem
  27. extern bool SDL_InitKeyboard(void);
  28. // Return whether a device is actually a keyboard
  29. extern bool SDL_IsKeyboard(Uint16 vendor, Uint16 product, int num_keys);
  30. // A keyboard has been added to the system
  31. extern void SDL_AddKeyboard(SDL_KeyboardID keyboardID, const char *name, bool send_event);
  32. // A keyboard has been removed from the system
  33. extern void SDL_RemoveKeyboard(SDL_KeyboardID keyboardID, bool send_event);
  34. // Set the mapping of scancode to key codes
  35. extern void SDL_SetKeymap(SDL_Keymap *keymap, bool send_event);
  36. // Set the keyboard focus window
  37. extern bool SDL_SetKeyboardFocus(SDL_Window *window);
  38. /* Send a character from an on-screen keyboard as scancode and modifier key events,
  39. currently assuming ASCII characters on a US keyboard layout
  40. */
  41. extern void SDL_SendKeyboardUnicodeKey(Uint64 timestamp, Uint32 ch);
  42. // Send a keyboard key event
  43. extern bool SDL_SendKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, bool down);
  44. extern bool SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, bool down);
  45. extern bool SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode);
  46. /* This is for platforms that don't know the keymap but can report scancode and keycode directly.
  47. Most platforms should prefer to optionally call SDL_SetKeymap and then use SDL_SendKeyboardKey. */
  48. extern bool SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, SDL_Keycode keycode, bool down);
  49. // Release all the autorelease keys
  50. extern void SDL_ReleaseAutoReleaseKeys(void);
  51. // Return true if any hardware key is pressed
  52. extern bool SDL_HardwareKeyboardKeyPressed(void);
  53. // Send keyboard text input
  54. extern void SDL_SendKeyboardText(const char *text);
  55. // Send editing text for selected range from start to end
  56. extern void SDL_SendEditingText(const char *text, int start, int length);
  57. // Send editing text candidates, which will be copied into the event
  58. extern void SDL_SendEditingTextCandidates(char **candidates, int num_candidates, int selected_candidate, bool horizontal);
  59. // Shutdown the keyboard subsystem
  60. extern void SDL_QuitKeyboard(void);
  61. // Toggle on or off pieces of the keyboard mod state.
  62. extern void SDL_ToggleModState(const SDL_Keymod modstate, const bool toggle);
  63. #endif // SDL_keyboard_c_h_