SDL_keyboard.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2021 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. /**
  19. * \file SDL_keyboard.h
  20. *
  21. * Include file for SDL keyboard event handling
  22. */
  23. #ifndef SDL_keyboard_h_
  24. #define SDL_keyboard_h_
  25. #include "SDL_stdinc.h"
  26. #include "SDL_error.h"
  27. #include "SDL_keycode.h"
  28. #include "SDL_video.h"
  29. #include "begin_code.h"
  30. /* Set up for C function definitions, even when using C++ */
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /**
  35. * \brief The SDL keysym structure, used in key events.
  36. *
  37. * \note If you are looking for translated character input, see the ::SDL_TEXTINPUT event.
  38. */
  39. typedef struct SDL_Keysym
  40. {
  41. SDL_Scancode scancode; /**< SDL physical key code - see ::SDL_Scancode for details */
  42. SDL_Keycode sym; /**< SDL virtual key code - see ::SDL_Keycode for details */
  43. Uint16 mod; /**< current key modifiers */
  44. Uint32 unused;
  45. } SDL_Keysym;
  46. /* Function prototypes */
  47. /**
  48. * Query the window which currently has keyboard focus.
  49. *
  50. * \returns the window with keyboard focus.
  51. */
  52. extern DECLSPEC SDL_Window * SDLCALL SDL_GetKeyboardFocus(void);
  53. /**
  54. * Get a snapshot of the current state of the keyboard.
  55. *
  56. * The pointer returned is a pointer to an internal SDL array. It will be
  57. * valid for the whole lifetime of the application and should not be freed
  58. * by the caller.
  59. *
  60. * A array element with a value of 1 means that the key is pressed and a value
  61. * of 0 means that it is not. Indexes into this array are obtained by using
  62. * SDL_Scancode values.
  63. *
  64. * Use SDL_PumpEvents() to update the state array.
  65. *
  66. * This function gives you the current state after all events have been
  67. * processed, so if a key or button has been pressed and released before you
  68. * process events, then the pressed state will never show up in the
  69. * SDL_GetKeyboardState() calls.
  70. *
  71. * Note: This function doesn't take into account whether shift has been
  72. * pressed or not.
  73. *
  74. * \param numkeys if non-NULL, receives the length of the returned array
  75. * \returns a pointer to an array of key states.
  76. *
  77. * \sa SDL_PumpEvents
  78. */
  79. extern DECLSPEC const Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys);
  80. /**
  81. * Get the current key modifier state for the keyboard.
  82. *
  83. * \returns an OR'd combination of the modifier keys for the keyboard. See
  84. * SDL_Keymod for details.
  85. *
  86. * \sa SDL_GetKeyboardState
  87. * \sa SDL_SetModState
  88. */
  89. extern DECLSPEC SDL_Keymod SDLCALL SDL_GetModState(void);
  90. /**
  91. * Set the current key modifier state for the keyboard.
  92. *
  93. * The inverse of SDL_GetModState(), SDL_SetModState() allows you to impose
  94. * modifier key states on your application. Simply pass your desired modifier
  95. * states into `modstate`. This value may be a bitwise, OR'd combination of
  96. * SDL_Keymod values.
  97. *
  98. * This does not change the keyboard state, only the key modifier flags that
  99. * SDL reports.
  100. *
  101. * \param modstate the desired SDL_Keymod for the keyboard
  102. *
  103. * \sa SDL_GetModState
  104. */
  105. extern DECLSPEC void SDLCALL SDL_SetModState(SDL_Keymod modstate);
  106. /**
  107. * Get the key code corresponding to the given scancode
  108. * according to the current keyboard layout.
  109. *
  110. * See SDL_Keycode for details.
  111. *
  112. * \param scancode the desired SDL_Scancode to query
  113. * \returns the SDL_Keycode that corresponds to the given SDL_Scancode.
  114. *
  115. * \sa SDL_GetKeyName
  116. * \sa SDL_GetScancodeFromKey
  117. */
  118. extern DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromScancode(SDL_Scancode scancode);
  119. /**
  120. * Get the scancode corresponding to the given key code
  121. * according to the current keyboard layout.
  122. *
  123. * See SDL_Scancode for details.
  124. *
  125. * \param key the desired SDL_Keycode to query
  126. * \returns the SDL_Scancode that corresponds to the given SDL_Keycode.
  127. *
  128. * \sa SDL_GetKeyFromScancode
  129. * \sa SDL_GetScancodeName
  130. */
  131. extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key);
  132. /**
  133. * Get a human-readable name for a scancode.
  134. *
  135. * See SDL_Scancode for details.
  136. *
  137. * **Warning**: The returned name is by design not stable across platforms,
  138. * e.g. the name for `SDL_SCANCODE_LGUI` is "Left GUI" under Linux but "Left
  139. * Windows" under Microsoft Windows, and some scancodes like
  140. * `SDL_SCANCODE_NONUSBACKSLASH` don't have any name at all. There are even
  141. * scancodes that share names, e.g. `SDL_SCANCODE_RETURN` and
  142. * `SDL_SCANCODE_RETURN2` (both called "Return"). This function is therefore
  143. * unsuitable for creating a stable cross-platform two-way mapping between
  144. * strings and scancodes.
  145. *
  146. * \param scancode the desired SDL_Scancode to query
  147. * \returns a pointer to the name for the scancode. If the scancode doesn't
  148. * have a name this function returns an empty string ("").
  149. *
  150. * \since This function is available since SDL 2.0.0.
  151. *
  152. * \sa SDL_GetScancodeFromKey
  153. * \sa SDL_GetScancodeFromName
  154. */
  155. extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_Scancode scancode);
  156. /**
  157. * Get a scancode from a human-readable name.
  158. *
  159. * \param name the human-readable scancode name
  160. * \returns the SDL_Scancode, or `SDL_SCANCODE_UNKNOWN` if the name wasn't
  161. * recognized; call SDL_GetError() for more information.
  162. *
  163. * \since This function is available since SDL 2.0.0.
  164. *
  165. * \sa SDL_GetKeyFromName
  166. * \sa SDL_GetScancodeFromKey
  167. * \sa SDL_GetScancodeName
  168. */
  169. extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *name);
  170. /**
  171. * Get a human-readable name for a key.
  172. *
  173. * See SDL_Scancode and SDL_Keycode for details.
  174. *
  175. * \param key the desired SDL_Keycode to query
  176. * \returns a pointer to a UTF-8 string that stays valid at least until the
  177. * next call to this function. If you need it around any longer, you
  178. * must copy it. If the key doesn't have a name, this function
  179. * returns an empty string ("").
  180. *
  181. * \sa SDL_GetKeyFromName
  182. * \sa SDL_GetKeyFromScancode
  183. * \sa SDL_GetScancodeFromKey
  184. */
  185. extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDL_Keycode key);
  186. /**
  187. * Get a key code from a human-readable name.
  188. *
  189. * \param name the human-readable key name
  190. * \returns key code, or `SDLK_UNKNOWN` if the name wasn't recognized; call
  191. * SDL_GetError() for more information.
  192. *
  193. * \sa SDL_GetKeyFromScancode
  194. * \sa SDL_GetKeyName
  195. * \sa SDL_GetScancodeFromName
  196. */
  197. extern DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name);
  198. /**
  199. * Start accepting Unicode text input events.
  200. *
  201. * This function will start accepting Unicode text input events in the focused
  202. * SDL window, and start emitting SDL_TextInputEvent (SDL_TEXTINPUT) and
  203. * SDL_TextEditingEvent (SDL_TEXTEDITING) events. Please use this function
  204. * in pair with SDL_StopTextInput().
  205. *
  206. * On some platforms using this function activates the screen keyboard.
  207. *
  208. * \sa SDL_SetTextInputRect
  209. * \sa SDL_StopTextInput
  210. */
  211. extern DECLSPEC void SDLCALL SDL_StartTextInput(void);
  212. /**
  213. * Check whether or not Unicode text input events are enabled.
  214. *
  215. * \returns SDL_TRUE if text input events are enabled else SDL_FALSE.
  216. *
  217. * \since This function is available since SDL 2.0.0.
  218. *
  219. * \sa SDL_StartTextInput
  220. */
  221. extern DECLSPEC SDL_bool SDLCALL SDL_IsTextInputActive(void);
  222. /**
  223. * Stop receiving any text input events.
  224. *
  225. * \sa SDL_StartTextInput
  226. */
  227. extern DECLSPEC void SDLCALL SDL_StopTextInput(void);
  228. /**
  229. * Set the rectangle used to type Unicode text inputs.
  230. *
  231. * \param rect the SDL_Rect structure representing the rectangle to receive
  232. * text (ignored if NULL)
  233. *
  234. * \sa SDL_StartTextInput
  235. */
  236. extern DECLSPEC void SDLCALL SDL_SetTextInputRect(SDL_Rect *rect);
  237. /**
  238. * Check whether the platform has screen keyboard support.
  239. *
  240. * \returns SDL_TRUE if the platform has some screen keyboard support or
  241. * SDL_FALSE if not.
  242. *
  243. * \since This function is available since SDL 2.0.0.
  244. *
  245. * \sa SDL_StartTextInput
  246. * \sa SDL_IsScreenKeyboardShown
  247. */
  248. extern DECLSPEC SDL_bool SDLCALL SDL_HasScreenKeyboardSupport(void);
  249. /**
  250. * Check whether the screen keyboard is shown for given window.
  251. *
  252. * \param window the window for which screen keyboard should be queried
  253. * \returns SDL_TRUE if screen keyboard is shown or SDL_FALSE if not.
  254. *
  255. * \since This function is available since SDL 2.0.0.
  256. *
  257. * \sa SDL_HasScreenKeyboardSupport
  258. */
  259. extern DECLSPEC SDL_bool SDLCALL SDL_IsScreenKeyboardShown(SDL_Window *window);
  260. /* Ends C function definitions when using C++ */
  261. #ifdef __cplusplus
  262. }
  263. #endif
  264. #include "close_code.h"
  265. #endif /* SDL_keyboard_h_ */
  266. /* vi: set ts=4 sw=4 expandtab: */