SDL  2.0
SDL_keyboard.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 /**
23  * \file SDL_keyboard.h
24  *
25  * Include file for SDL keyboard event handling
26  */
27 
28 #ifndef SDL_keyboard_h_
29 #define SDL_keyboard_h_
30 
31 #include "SDL_stdinc.h"
32 #include "SDL_error.h"
33 #include "SDL_keycode.h"
34 #include "SDL_video.h"
35 
36 #include "begin_code.h"
37 /* Set up for C function definitions, even when using C++ */
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /**
43  * \brief The SDL keysym structure, used in key events.
44  *
45  * \note If you are looking for translated character input, see the ::SDL_TEXTINPUT event.
46  */
47 typedef struct SDL_Keysym
48 {
49  SDL_Scancode scancode; /**< SDL physical key code - see ::SDL_Scancode for details */
50  SDL_Keycode sym; /**< SDL virtual key code - see ::SDL_Keycode for details */
51  Uint16 mod; /**< current key modifiers */
53 } SDL_Keysym;
54 
55 /* Function prototypes */
56 
57 /**
58  * \brief Get the window which currently has keyboard focus.
59  */
61 
62 /**
63  * \brief Get a snapshot of the current state of the keyboard.
64  *
65  * \param numkeys if non-NULL, receives the length of the returned array.
66  *
67  * \return An array of key states. Indexes into this array are obtained by using ::SDL_Scancode values.
68  *
69  * \b Example:
70  * \code
71  * const Uint8 *state = SDL_GetKeyboardState(NULL);
72  * if ( state[SDL_SCANCODE_RETURN] ) {
73  * printf("<RETURN> is pressed.\n");
74  * }
75  * \endcode
76  */
77 extern DECLSPEC const Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys);
78 
79 /**
80  * \brief Get the current key modifier state for the keyboard.
81  */
83 
84 /**
85  * \brief Set the current key modifier state for the keyboard.
86  *
87  * \note This does not change the keyboard state, only the key modifier flags.
88  */
89 extern DECLSPEC void SDLCALL SDL_SetModState(SDL_Keymod modstate);
90 
91 /**
92  * \brief Get the key code corresponding to the given scancode according
93  * to the current keyboard layout.
94  *
95  * See ::SDL_Keycode for details.
96  *
97  * \sa SDL_GetKeyName()
98  */
100 
101 /**
102  * \brief Get the scancode corresponding to the given key code according to the
103  * current keyboard layout.
104  *
105  * See ::SDL_Scancode for details.
106  *
107  * \sa SDL_GetScancodeName()
108  */
110 
111 /**
112  * \brief Get a human-readable name for a scancode.
113  *
114  * \return A pointer to the name for the scancode.
115  * If the scancode doesn't have a name, this function returns
116  * an empty string ("").
117  *
118  * \sa SDL_Scancode
119  */
120 extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_Scancode scancode);
121 
122 /**
123  * \brief Get a scancode from a human-readable name
124  *
125  * \return scancode, or SDL_SCANCODE_UNKNOWN if the name wasn't recognized
126  *
127  * \sa SDL_Scancode
128  */
130 
131 /**
132  * \brief Get a human-readable name for a key.
133  *
134  * \return A pointer to a UTF-8 string that stays valid at least until the next
135  * call to this function. If you need it around any longer, you must
136  * copy it. If the key doesn't have a name, this function returns an
137  * empty string ("").
138  *
139  * \sa SDL_Keycode
140  */
141 extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDL_Keycode key);
142 
143 /**
144  * \brief Get a key code from a human-readable name
145  *
146  * \return key code, or SDLK_UNKNOWN if the name wasn't recognized
147  *
148  * \sa SDL_Keycode
149  */
151 
152 /**
153  * \brief Start accepting Unicode text input events.
154  * This function will show the on-screen keyboard if supported.
155  *
156  * \sa SDL_StopTextInput()
157  * \sa SDL_SetTextInputRect()
158  * \sa SDL_HasScreenKeyboardSupport()
159  */
160 extern DECLSPEC void SDLCALL SDL_StartTextInput(void);
161 
162 /**
163  * \brief Return whether or not Unicode text input events are enabled.
164  *
165  * \sa SDL_StartTextInput()
166  * \sa SDL_StopTextInput()
167  */
169 
170 /**
171  * \brief Stop receiving any text input events.
172  * This function will hide the on-screen keyboard if supported.
173  *
174  * \sa SDL_StartTextInput()
175  * \sa SDL_HasScreenKeyboardSupport()
176  */
177 extern DECLSPEC void SDLCALL SDL_StopTextInput(void);
178 
179 /**
180  * \brief Set the rectangle used to type Unicode text inputs.
181  * This is used as a hint for IME and on-screen keyboard placement.
182  *
183  * \sa SDL_StartTextInput()
184  */
186 
187 /**
188  * \brief Returns whether the platform has some screen keyboard support.
189  *
190  * \return SDL_TRUE if some keyboard support is available else SDL_FALSE.
191  *
192  * \note Not all screen keyboard functions are supported on all platforms.
193  *
194  * \sa SDL_IsScreenKeyboardShown()
195  */
197 
198 /**
199  * \brief Returns whether the screen keyboard is shown for given window.
200  *
201  * \param window The window for which screen keyboard should be queried.
202  *
203  * \return SDL_TRUE if screen keyboard is shown else SDL_FALSE.
204  *
205  * \sa SDL_HasScreenKeyboardSupport()
206  */
208 
209 /* Ends C function definitions when using C++ */
210 #ifdef __cplusplus
211 }
212 #endif
213 #include "close_code.h"
214 
215 #endif /* SDL_keyboard_h_ */
216 
217 /* vi: set ts=4 sw=4 expandtab: */
DECLSPEC
#define DECLSPEC
Definition: SDL_internal.h:48
SDL_GetScancodeName
const char * SDL_GetScancodeName(SDL_Scancode scancode)
Get a human-readable name for a scancode.
Definition: SDL_keyboard.c:905
SDL_SetTextInputRect
void SDL_SetTextInputRect(SDL_Rect *rect)
Set the rectangle used to type Unicode text inputs. This is used as a hint for IME and on-screen keyb...
Definition: SDL_video.c:3803
SDL_StartTextInput
void SDL_StartTextInput(void)
Start accepting Unicode text input events. This function will show the on-screen keyboard if supporte...
Definition: SDL_video.c:3755
SDL_GetModState
SDL_Keymod SDL_GetModState(void)
Get the current key modifier state for the keyboard.
Definition: SDL_keyboard.c:848
SDL_Keysym::unused
Uint32 unused
Definition: SDL_keyboard.h:52
SDL_GetKeyFromName
SDL_Keycode SDL_GetKeyFromName(const char *name)
Get a key code from a human-readable name.
Definition: SDL_keyboard.c:982
SDL_error.h
SDL_Keysym::scancode
SDL_Scancode scancode
Definition: SDL_keyboard.h:49
SDL_keycode.h
SDL_SetModState
void SDL_SetModState(SDL_Keymod modstate)
Set the current key modifier state for the keyboard.
Definition: SDL_keyboard.c:856
SDLCALL
#define SDLCALL
Definition: SDL_internal.h:49
SDL_Scancode
SDL_Scancode
The SDL keyboard scancode representation.
Definition: SDL_scancode.h:43
SDL_GetScancodeFromKey
SDL_Scancode SDL_GetScancodeFromKey(SDL_Keycode key)
Get the scancode corresponding to the given key code according to the current keyboard layout.
Definition: SDL_keyboard.c:890
SDL_GetKeyName
const char * SDL_GetKeyName(SDL_Keycode key)
Get a human-readable name for a key.
Definition: SDL_keyboard.c:943
SDL_Keymod
SDL_Keymod
Enumeration of valid key mods (possibly OR'd together).
Definition: SDL_keycode.h:325
SDL_Keycode
Sint32 SDL_Keycode
The SDL virtual key representation.
Definition: SDL_keycode.h:45
close_code.h
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:73
SDL_HasScreenKeyboardSupport
SDL_bool SDL_HasScreenKeyboardSupport(void)
Returns whether the platform has some screen keyboard support.
Definition: SDL_video.c:3811
begin_code.h
SDL_IsScreenKeyboardShown
SDL_bool SDL_IsScreenKeyboardShown(SDL_Window *window)
Returns whether the screen keyboard is shown for given window.
Definition: SDL_video.c:3820
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:179
SDL_IsTextInputActive
SDL_bool SDL_IsTextInputActive(void)
Return whether or not Unicode text input events are enabled.
Definition: SDL_video.c:3776
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_GetKeyboardFocus
SDL_Window * SDL_GetKeyboardFocus(void)
Get the window which currently has keyboard focus.
Definition: SDL_keyboard.c:622
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
rect
SDL_Rect rect
Definition: testrelative.c:27
SDL_GetScancodeFromName
SDL_Scancode SDL_GetScancodeFromName(const char *name)
Get a scancode from a human-readable name.
Definition: SDL_keyboard.c:920
SDL_GetKeyFromScancode
SDL_Keycode SDL_GetKeyFromScancode(SDL_Scancode scancode)
Get the key code corresponding to the given scancode according to the current keyboard layout.
Definition: SDL_keyboard.c:877
key
GLuint64 key
Definition: gl2ext.h:2192
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:161
SDL_Rect
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77
SDL_Keysym::sym
SDL_Keycode sym
Definition: SDL_keyboard.h:50
SDL_stdinc.h
SDL_Keysym
The SDL keysym structure, used in key events.
Definition: SDL_keyboard.h:47
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
SDL_Keysym::mod
Uint16 mod
Definition: SDL_keyboard.h:51
SDL_video.h
SDL_GetKeyboardState
const Uint8 * SDL_GetKeyboardState(int *numkeys)
Get a snapshot of the current state of the keyboard.
Definition: SDL_keyboard.c:837
SDL_StopTextInput
void SDL_StopTextInput(void)
Stop receiving any text input events. This function will hide the on-screen keyboard if supported.
Definition: SDL_video.c:3782
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:191