🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

337 lines
10 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 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. * \since This function is available since SDL 2.0.0.
  53. */
  54. extern DECLSPEC SDL_Window * SDLCALL SDL_GetKeyboardFocus(void);
  55. /**
  56. * Get a snapshot of the current state of the keyboard.
  57. *
  58. * The pointer returned is a pointer to an internal SDL array. It will be
  59. * valid for the whole lifetime of the application and should not be freed by
  60. * the caller.
  61. *
  62. * A array element with a value of 1 means that the key is pressed and a value
  63. * of 0 means that it is not. Indexes into this array are obtained by using
  64. * SDL_Scancode values.
  65. *
  66. * Use SDL_PumpEvents() to update the state array.
  67. *
  68. * This function gives you the current state after all events have been
  69. * processed, so if a key or button has been pressed and released before you
  70. * process events, then the pressed state will never show up in the
  71. * SDL_GetKeyboardState() calls.
  72. *
  73. * Note: This function doesn't take into account whether shift has been
  74. * pressed or not.
  75. *
  76. * \param numkeys if non-NULL, receives the length of the returned array
  77. * \returns a pointer to an array of key states.
  78. *
  79. * \since This function is available since SDL 2.0.0.
  80. *
  81. * \sa SDL_PumpEvents
  82. */
  83. extern DECLSPEC const Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys);
  84. /**
  85. * Get the current key modifier state for the keyboard.
  86. *
  87. * \returns an OR'd combination of the modifier keys for the keyboard. See
  88. * SDL_Keymod for details.
  89. *
  90. * \since This function is available since SDL 2.0.0.
  91. *
  92. * \sa SDL_GetKeyboardState
  93. * \sa SDL_SetModState
  94. */
  95. extern DECLSPEC SDL_Keymod SDLCALL SDL_GetModState(void);
  96. /**
  97. * Set the current key modifier state for the keyboard.
  98. *
  99. * The inverse of SDL_GetModState(), SDL_SetModState() allows you to impose
  100. * modifier key states on your application. Simply pass your desired modifier
  101. * states into `modstate`. This value may be a bitwise, OR'd combination of
  102. * SDL_Keymod values.
  103. *
  104. * This does not change the keyboard state, only the key modifier flags that
  105. * SDL reports.
  106. *
  107. * \param modstate the desired SDL_Keymod for the keyboard
  108. *
  109. * \since This function is available since SDL 2.0.0.
  110. *
  111. * \sa SDL_GetModState
  112. */
  113. extern DECLSPEC void SDLCALL SDL_SetModState(SDL_Keymod modstate);
  114. /**
  115. * Get the key code corresponding to the given scancode according to the
  116. * current keyboard layout.
  117. *
  118. * See SDL_Keycode for details.
  119. *
  120. * \param scancode the desired SDL_Scancode to query
  121. * \returns the SDL_Keycode that corresponds to the given SDL_Scancode.
  122. *
  123. * \since This function is available since SDL 2.0.0.
  124. *
  125. * \sa SDL_GetKeyName
  126. * \sa SDL_GetScancodeFromKey
  127. */
  128. extern DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromScancode(SDL_Scancode scancode);
  129. /**
  130. * Get the scancode corresponding to the given key code according to the
  131. * current keyboard layout.
  132. *
  133. * See SDL_Scancode for details.
  134. *
  135. * \param key the desired SDL_Keycode to query
  136. * \returns the SDL_Scancode that corresponds to the given SDL_Keycode.
  137. *
  138. * \since This function is available since SDL 2.0.0.
  139. *
  140. * \sa SDL_GetKeyFromScancode
  141. * \sa SDL_GetScancodeName
  142. */
  143. extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key);
  144. /**
  145. * Get a human-readable name for a scancode.
  146. *
  147. * See SDL_Scancode for details.
  148. *
  149. * **Warning**: The returned name is by design not stable across platforms,
  150. * e.g. the name for `SDL_SCANCODE_LGUI` is "Left GUI" under Linux but "Left
  151. * Windows" under Microsoft Windows, and some scancodes like
  152. * `SDL_SCANCODE_NONUSBACKSLASH` don't have any name at all. There are even
  153. * scancodes that share names, e.g. `SDL_SCANCODE_RETURN` and
  154. * `SDL_SCANCODE_RETURN2` (both called "Return"). This function is therefore
  155. * unsuitable for creating a stable cross-platform two-way mapping between
  156. * strings and scancodes.
  157. *
  158. * \param scancode the desired SDL_Scancode to query
  159. * \returns a pointer to the name for the scancode. If the scancode doesn't
  160. * have a name this function returns an empty string ("").
  161. *
  162. * \since This function is available since SDL 2.0.0.
  163. *
  164. * \sa SDL_GetScancodeFromKey
  165. * \sa SDL_GetScancodeFromName
  166. */
  167. extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_Scancode scancode);
  168. /**
  169. * Get a scancode from a human-readable name.
  170. *
  171. * \param name the human-readable scancode name
  172. * \returns the SDL_Scancode, or `SDL_SCANCODE_UNKNOWN` if the name wasn't
  173. * recognized; call SDL_GetError() for more information.
  174. *
  175. * \since This function is available since SDL 2.0.0.
  176. *
  177. * \sa SDL_GetKeyFromName
  178. * \sa SDL_GetScancodeFromKey
  179. * \sa SDL_GetScancodeName
  180. */
  181. extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *name);
  182. /**
  183. * Get a human-readable name for a key.
  184. *
  185. * See SDL_Scancode and SDL_Keycode for details.
  186. *
  187. * \param key the desired SDL_Keycode to query
  188. * \returns a pointer to a UTF-8 string that stays valid at least until the
  189. * next call to this function. If you need it around any longer, you
  190. * must copy it. If the key doesn't have a name, this function
  191. * returns an empty string ("").
  192. *
  193. * \since This function is available since SDL 2.0.0.
  194. *
  195. * \sa SDL_GetKeyFromName
  196. * \sa SDL_GetKeyFromScancode
  197. * \sa SDL_GetScancodeFromKey
  198. */
  199. extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDL_Keycode key);
  200. /**
  201. * Get a key code from a human-readable name.
  202. *
  203. * \param name the human-readable key name
  204. * \returns key code, or `SDLK_UNKNOWN` if the name wasn't recognized; call
  205. * SDL_GetError() for more information.
  206. *
  207. * \since This function is available since SDL 2.0.0.
  208. *
  209. * \sa SDL_GetKeyFromScancode
  210. * \sa SDL_GetKeyName
  211. * \sa SDL_GetScancodeFromName
  212. */
  213. extern DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name);
  214. /**
  215. * Start accepting Unicode text input events.
  216. *
  217. * This function will start accepting Unicode text input events in the focused
  218. * SDL window, and start emitting SDL_TextInputEvent (SDL_TEXTINPUT) and
  219. * SDL_TextEditingEvent (SDL_TEXTEDITING) events. Please use this function in
  220. * pair with SDL_StopTextInput().
  221. *
  222. * On some platforms using this function activates the screen keyboard.
  223. *
  224. * \since This function is available since SDL 2.0.0.
  225. *
  226. * \sa SDL_SetTextInputRect
  227. * \sa SDL_StopTextInput
  228. */
  229. extern DECLSPEC void SDLCALL SDL_StartTextInput(void);
  230. /**
  231. * Check whether or not Unicode text input events are enabled.
  232. *
  233. * \returns SDL_TRUE if text input events are enabled else SDL_FALSE.
  234. *
  235. * \since This function is available since SDL 2.0.0.
  236. *
  237. * \sa SDL_StartTextInput
  238. */
  239. extern DECLSPEC SDL_bool SDLCALL SDL_IsTextInputActive(void);
  240. /**
  241. * Stop receiving any text input events.
  242. *
  243. * \since This function is available since SDL 2.0.0.
  244. *
  245. * \sa SDL_StartTextInput
  246. */
  247. extern DECLSPEC void SDLCALL SDL_StopTextInput(void);
  248. /**
  249. * Dismiss the composition window/IME without disabling the subsystem.
  250. *
  251. * \since This function is available since SDL 2.0.22.
  252. *
  253. * \sa SDL_StartTextInput
  254. * \sa SDL_StopTextInput
  255. */
  256. extern DECLSPEC void SDLCALL SDL_ClearComposition(void);
  257. /**
  258. * Returns if an IME Composite or Candidate window is currently shown.
  259. *
  260. * \since This function is available since SDL 2.0.22.
  261. */
  262. extern DECLSPEC SDL_bool SDLCALL SDL_IsTextInputShown(void);
  263. /**
  264. * Set the rectangle used to type Unicode text inputs.
  265. *
  266. * Note: If you want use system native IME window, try to set hint
  267. * **SDL_HINT_IME_SHOW_UI** to **1**, otherwise this function won't give you
  268. * any feedback.
  269. *
  270. * \param rect the SDL_Rect structure representing the rectangle to receive
  271. * text (ignored if NULL)
  272. *
  273. * \since This function is available since SDL 2.0.0.
  274. *
  275. * \sa SDL_StartTextInput
  276. */
  277. extern DECLSPEC void SDLCALL SDL_SetTextInputRect(SDL_Rect *rect);
  278. /**
  279. * Check whether the platform has screen keyboard support.
  280. *
  281. * \returns SDL_TRUE if the platform has some screen keyboard support or
  282. * SDL_FALSE if not.
  283. *
  284. * \since This function is available since SDL 2.0.0.
  285. *
  286. * \sa SDL_StartTextInput
  287. * \sa SDL_IsScreenKeyboardShown
  288. */
  289. extern DECLSPEC SDL_bool SDLCALL SDL_HasScreenKeyboardSupport(void);
  290. /**
  291. * Check whether the screen keyboard is shown for given window.
  292. *
  293. * \param window the window for which screen keyboard should be queried
  294. * \returns SDL_TRUE if screen keyboard is shown or SDL_FALSE if not.
  295. *
  296. * \since This function is available since SDL 2.0.0.
  297. *
  298. * \sa SDL_HasScreenKeyboardSupport
  299. */
  300. extern DECLSPEC SDL_bool SDLCALL SDL_IsScreenKeyboardShown(SDL_Window *window);
  301. /* Ends C function definitions when using C++ */
  302. #ifdef __cplusplus
  303. }
  304. #endif
  305. #include "close_code.h"
  306. #endif /* SDL_keyboard_h_ */
  307. /* vi: set ts=4 sw=4 expandtab: */