SDL  2.0
SDL_keyboard.h File Reference
#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "SDL_keycode.h"
#include "SDL_video.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_keyboard.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_Keysym
 The SDL keysym structure, used in key events. More...
 

Functions

SDL_WindowSDL_GetKeyboardFocus (void)
 Get the window which currently has keyboard focus. More...
 
const Uint8SDL_GetKeyboardState (int *numkeys)
 Get a snapshot of the current state of the keyboard. More...
 
SDL_Keymod SDL_GetModState (void)
 Get the current key modifier state for the keyboard. More...
 
void SDL_SetModState (SDL_Keymod modstate)
 Set the current key modifier state for the keyboard. More...
 
SDL_Keycode SDL_GetKeyFromScancode (SDL_Scancode scancode)
 Get the key code corresponding to the given scancode according to the current keyboard layout. More...
 
SDL_Scancode SDL_GetScancodeFromKey (SDL_Keycode key)
 Get the scancode corresponding to the given key code according to the current keyboard layout. More...
 
const char * SDL_GetScancodeName (SDL_Scancode scancode)
 Get a human-readable name for a scancode. More...
 
SDL_Scancode SDL_GetScancodeFromName (const char *name)
 Get a scancode from a human-readable name. More...
 
const char * SDL_GetKeyName (SDL_Keycode key)
 Get a human-readable name for a key. More...
 
SDL_Keycode SDL_GetKeyFromName (const char *name)
 Get a key code from a human-readable name. More...
 
void SDL_StartTextInput (void)
 Start accepting Unicode text input events. This function will show the on-screen keyboard if supported. More...
 
SDL_bool SDL_IsTextInputActive (void)
 Return whether or not Unicode text input events are enabled. More...
 
void SDL_StopTextInput (void)
 Stop receiving any text input events. This function will hide the on-screen keyboard if supported. More...
 
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 keyboard placement. More...
 
SDL_bool SDL_HasScreenKeyboardSupport (void)
 Returns whether the platform has some screen keyboard support. More...
 
SDL_bool SDL_IsScreenKeyboardShown (SDL_Window *window)
 Returns whether the screen keyboard is shown for given window. More...
 

Detailed Description

Include file for SDL keyboard event handling

Definition in file SDL_keyboard.h.

Function Documentation

◆ SDL_GetKeyboardFocus()

SDL_Window* SDL_GetKeyboardFocus ( void  )

Get the window which currently has keyboard focus.

Definition at line 247 of file SDL_dynapi_procs.h.

References SDL_Keyboard::focus, and SDL_keyboard.

◆ SDL_GetKeyboardState()

const Uint8* SDL_GetKeyboardState ( int numkeys)

Get a snapshot of the current state of the keyboard.

Parameters
numkeysif non-NULL, receives the length of the returned array.
Returns
An array of key states. Indexes into this array are obtained by using SDL_Scancode values.

Example:

printf("<RETURN> is pressed.\n");
}
#define SDL_GetKeyboardState
@ SDL_SCANCODE_RETURN
Definition: SDL_scancode.h:92
uint8_t Uint8
Definition: SDL_stdinc.h:185
struct xkb_state * state
#define NULL
Definition: begin_code.h:163

Definition at line 896 of file SDL_keyboard.c.

897 {
898  SDL_Keyboard *keyboard = &SDL_keyboard;
899 
900  if (numkeys != (int *) 0) {
901  *numkeys = SDL_NUM_SCANCODES;
902  }
903  return keyboard->keystate;
904 }
static SDL_Keyboard SDL_keyboard
Definition: SDL_keyboard.c:51
@ SDL_NUM_SCANCODES
Definition: SDL_scancode.h:407
Uint8 keystate[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:46

References SDL_Keyboard::keystate, SDL_keyboard, and SDL_NUM_SCANCODES.

◆ SDL_GetKeyFromName()

SDL_Keycode SDL_GetKeyFromName ( const char *  name)

Get a key code from a human-readable name.

Returns
key code, or SDLK_UNKNOWN if the name wasn't recognized
See also
SDL_Keycode

Definition at line 1041 of file SDL_keyboard.c.

1042 {
1043  SDL_Keycode key;
1044 
1045  /* Check input */
1046  if (name == NULL) {
1047  return SDLK_UNKNOWN;
1048  }
1049 
1050  /* If it's a single UTF-8 character, then that's the keycode itself */
1051  key = *(const unsigned char *)name;
1052  if (key >= 0xF0) {
1053  if (SDL_strlen(name) == 4) {
1054  int i = 0;
1055  key = (Uint16)(name[i]&0x07) << 18;
1056  key |= (Uint16)(name[++i]&0x3F) << 12;
1057  key |= (Uint16)(name[++i]&0x3F) << 6;
1058  key |= (Uint16)(name[++i]&0x3F);
1059  return key;
1060  }
1061  return SDLK_UNKNOWN;
1062  } else if (key >= 0xE0) {
1063  if (SDL_strlen(name) == 3) {
1064  int i = 0;
1065  key = (Uint16)(name[i]&0x0F) << 12;
1066  key |= (Uint16)(name[++i]&0x3F) << 6;
1067  key |= (Uint16)(name[++i]&0x3F);
1068  return key;
1069  }
1070  return SDLK_UNKNOWN;
1071  } else if (key >= 0xC0) {
1072  if (SDL_strlen(name) == 2) {
1073  int i = 0;
1074  key = (Uint16)(name[i]&0x1F) << 6;
1075  key |= (Uint16)(name[++i]&0x3F);
1076  return key;
1077  }
1078  return SDLK_UNKNOWN;
1079  } else {
1080  if (SDL_strlen(name) == 1) {
1081  if (key >= 'A' && key <= 'Z') {
1082  key += 32;
1083  }
1084  return key;
1085  }
1086 
1087  /* Get the scancode for this name, and the associated keycode */
1089  }
1090 }
#define SDL_strlen
SDL_Scancode SDL_GetScancodeFromName(const char *name)
Get a scancode from a human-readable name.
Definition: SDL_keyboard.c:979
static const SDL_Keycode SDL_default_keymap[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:53
@ SDLK_UNKNOWN
Definition: SDL_keycode.h:52
Sint32 SDL_Keycode
The SDL virtual key representation.
Definition: SDL_keycode.h:45
GLuint const GLchar * name
uint16_t Uint16
Definition: SDL_stdinc.h:197
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
GLuint64 key
Definition: gl2ext.h:2192

References i, NULL, SDL_default_keymap, SDL_GetScancodeFromName(), SDL_strlen, and SDLK_UNKNOWN.

◆ SDL_GetKeyFromScancode()

SDL_Keycode SDL_GetKeyFromScancode ( SDL_Scancode  scancode)

Get the key code corresponding to the given scancode according to the current keyboard layout.

See SDL_Keycode for details.

See also
SDL_GetKeyName()

Definition at line 936 of file SDL_keyboard.c.

937 {
938  SDL_Keyboard *keyboard = &SDL_keyboard;
939 
940  if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
941  SDL_InvalidParamError("scancode");
942  return 0;
943  }
944 
945  return keyboard->keymap[scancode];
946 }
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:90
@ SDL_SCANCODE_UNKNOWN
Definition: SDL_scancode.h:45
SDL_Keycode keymap[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:47

References SDL_Keyboard::keymap, SDL_InvalidParamError, SDL_keyboard, SDL_NUM_SCANCODES, and SDL_SCANCODE_UNKNOWN.

◆ SDL_GetKeyName()

const char* SDL_GetKeyName ( SDL_Keycode  key)

Get a human-readable name for a key.

Returns
A pointer to a UTF-8 string that stays valid at least until the next call to this function. If you need it around any longer, you must copy it. If the key doesn't have a name, this function returns an empty string ("").
See also
SDL_Keycode

Definition at line 1002 of file SDL_keyboard.c.

1003 {
1004  static char name[8];
1005  char *end;
1006 
1007  if (key & SDLK_SCANCODE_MASK) {
1008  return
1010  }
1011 
1012  switch (key) {
1013  case SDLK_RETURN:
1015  case SDLK_ESCAPE:
1017  case SDLK_BACKSPACE:
1019  case SDLK_TAB:
1021  case SDLK_SPACE:
1023  case SDLK_DELETE:
1025  default:
1026  /* Unaccented letter keys on latin keyboards are normally
1027  labeled in upper case (and probably on others like Greek or
1028  Cyrillic too, so if you happen to know for sure, please
1029  adapt this). */
1030  if (key >= 'a' && key <= 'z') {
1031  key -= 32;
1032  }
1033 
1035  *end = '\0';
1036  return name;
1037  }
1038 }
char * SDL_UCS4ToUTF8(Uint32 ch, char *dst)
Definition: SDL_keyboard.c:524
const char * SDL_GetScancodeName(SDL_Scancode scancode)
Get a human-readable name for a scancode.
Definition: SDL_keyboard.c:964
@ SDLK_BACKSPACE
Definition: SDL_keycode.h:56
@ SDLK_TAB
Definition: SDL_keycode.h:57
@ SDLK_ESCAPE
Definition: SDL_keycode.h:55
@ SDLK_SPACE
Definition: SDL_keycode.h:58
@ SDLK_DELETE
Definition: SDL_keycode.h:150
@ SDLK_RETURN
Definition: SDL_keycode.h:54
#define SDLK_SCANCODE_MASK
Definition: SDL_keycode.h:47
GLuint GLuint end
Definition: SDL_opengl.h:1571
SDL_Scancode
The SDL keyboard scancode representation.
Definition: SDL_scancode.h:44
@ SDL_SCANCODE_ESCAPE
Definition: SDL_scancode.h:93
@ SDL_SCANCODE_DELETE
Definition: SDL_scancode.h:173
@ SDL_SCANCODE_TAB
Definition: SDL_scancode.h:95
@ SDL_SCANCODE_BACKSPACE
Definition: SDL_scancode.h:94
@ SDL_SCANCODE_SPACE
Definition: SDL_scancode.h:96
uint32_t Uint32
Definition: SDL_stdinc.h:209

References SDL_GetScancodeName(), SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_DELETE, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_RETURN, SDL_SCANCODE_SPACE, SDL_SCANCODE_TAB, SDL_UCS4ToUTF8(), SDLK_BACKSPACE, SDLK_DELETE, SDLK_ESCAPE, SDLK_RETURN, SDLK_SCANCODE_MASK, SDLK_SPACE, and SDLK_TAB.

◆ SDL_GetModState()

SDL_Keymod SDL_GetModState ( void  )

Get the current key modifier state for the keyboard.

Definition at line 249 of file SDL_dynapi_procs.h.

References SDL_Keyboard::modstate, and SDL_keyboard.

◆ SDL_GetScancodeFromKey()

SDL_Scancode SDL_GetScancodeFromKey ( SDL_Keycode  key)

Get the scancode corresponding to the given key code according to the current keyboard layout.

See SDL_Scancode for details.

See also
SDL_GetScancodeName()

Definition at line 949 of file SDL_keyboard.c.

950 {
951  SDL_Keyboard *keyboard = &SDL_keyboard;
952  SDL_Scancode scancode;
953 
954  for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES;
955  ++scancode) {
956  if (keyboard->keymap[scancode] == key) {
957  return scancode;
958  }
959  }
960  return SDL_SCANCODE_UNKNOWN;
961 }

References SDL_Keyboard::keymap, SDL_keyboard, SDL_NUM_SCANCODES, and SDL_SCANCODE_UNKNOWN.

◆ SDL_GetScancodeFromName()

SDL_Scancode SDL_GetScancodeFromName ( const char *  name)

Get a scancode from a human-readable name.

Returns
scancode, or SDL_SCANCODE_UNKNOWN if the name wasn't recognized
See also
SDL_Scancode

Definition at line 979 of file SDL_keyboard.c.

980 {
981  int i;
982 
983  if (!name || !*name) {
984  SDL_InvalidParamError("name");
985  return SDL_SCANCODE_UNKNOWN;
986  }
987 
988  for (i = 0; i < SDL_arraysize(SDL_scancode_names); ++i) {
989  if (!SDL_scancode_names[i]) {
990  continue;
991  }
992  if (SDL_strcasecmp(name, SDL_scancode_names[i]) == 0) {
993  return (SDL_Scancode)i;
994  }
995  }
996 
997  SDL_InvalidParamError("name");
998  return SDL_SCANCODE_UNKNOWN;
999 }
#define SDL_strcasecmp
static const char * SDL_scancode_names[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:286
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:121

References i, SDL_arraysize, SDL_InvalidParamError, SDL_scancode_names, SDL_SCANCODE_UNKNOWN, and SDL_strcasecmp.

Referenced by SDL_GetKeyFromName().

◆ SDL_GetScancodeName()

const char* SDL_GetScancodeName ( SDL_Scancode  scancode)

Get a human-readable name for a scancode.

Returns
A pointer to the name for the scancode. If the scancode doesn't have a name, this function returns an empty string ("").
See also
SDL_Scancode

Definition at line 964 of file SDL_keyboard.c.

965 {
966  const char *name;
967  if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
968  SDL_InvalidParamError("scancode");
969  return "";
970  }
971 
972  name = SDL_scancode_names[scancode];
973  if (name)
974  return name;
975  else
976  return "";
977 }

References SDL_InvalidParamError, SDL_NUM_SCANCODES, SDL_scancode_names, and SDL_SCANCODE_UNKNOWN.

Referenced by SDL_GetKeyName(), and SDL_SendKeyboardKeyInternal().

◆ SDL_HasScreenKeyboardSupport()

SDL_bool SDL_HasScreenKeyboardSupport ( void  )

Returns whether the platform has some screen keyboard support.

Returns
SDL_TRUE if some keyboard support is available else SDL_FALSE.
Note
Not all screen keyboard functions are supported on all platforms.
See also
SDL_IsScreenKeyboardShown()

Definition at line 261 of file SDL_dynapi_procs.h.

References _this, SDL_VideoDevice::HasScreenKeyboardSupport, and SDL_FALSE.

Referenced by SDL_VideoInit().

◆ SDL_IsScreenKeyboardShown()

SDL_bool SDL_IsScreenKeyboardShown ( SDL_Window window)

Returns whether the screen keyboard is shown for given window.

Parameters
windowThe window for which screen keyboard should be queried.
Returns
SDL_TRUE if screen keyboard is shown else SDL_FALSE.
See also
SDL_HasScreenKeyboardSupport()

Definition at line 3940 of file SDL_video.c.

3941 {
3942  if (window && _this && _this->IsScreenKeyboardShown) {
3944  }
3945  return SDL_FALSE;
3946 }
@ SDL_FALSE
Definition: SDL_stdinc.h:169
static SDL_VideoDevice * _this
Definition: SDL_video.c:126
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_bool(* IsScreenKeyboardShown)(_THIS, SDL_Window *window)
Definition: SDL_sysvideo.h:305

References _this, SDL_VideoDevice::IsScreenKeyboardShown, and SDL_FALSE.

◆ SDL_IsTextInputActive()

SDL_bool SDL_IsTextInputActive ( void  )

Return whether or not Unicode text input events are enabled.

See also
SDL_StartTextInput()
SDL_StopTextInput()

Definition at line 3896 of file SDL_video.c.

3897 {
3899 }
@ SDL_TEXTINPUT
Definition: SDL_events.h:101
#define SDL_GetEventState(type)
Definition: SDL_events.h:808
#define SDL_ENABLE
Definition: SDL_events.h:795

References SDL_ENABLE, SDL_GetEventState, and SDL_TEXTINPUT.

◆ SDL_SetModState()

void SDL_SetModState ( SDL_Keymod  modstate)

Set the current key modifier state for the keyboard.

Note
This does not change the keyboard state, only the key modifier flags.

Definition at line 915 of file SDL_keyboard.c.

916 {
917  SDL_Keyboard *keyboard = &SDL_keyboard;
918 
919  keyboard->modstate = modstate;
920 }
Uint16 modstate
Definition: SDL_keyboard.c:44

References SDL_Keyboard::modstate, and SDL_keyboard.

◆ 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 keyboard placement.

See also
SDL_StartTextInput()

Definition at line 3923 of file SDL_video.c.

3924 {
3925  if (_this && _this->SetTextInputRect) {
3927  }
3928 }
void(* SetTextInputRect)(_THIS, SDL_Rect *rect)
Definition: SDL_sysvideo.h:299
SDL_Rect rect
Definition: testrelative.c:27

References _this, rect, and SDL_VideoDevice::SetTextInputRect.

◆ SDL_StartTextInput()

void SDL_StartTextInput ( void  )

Start accepting Unicode text input events. This function will show the on-screen keyboard if supported.

See also
SDL_StopTextInput()
SDL_SetTextInputRect()
SDL_HasScreenKeyboardSupport()

Definition at line 257 of file SDL_dynapi_procs.h.

References _this, SDL_ENABLE, SDL_EventState, SDL_GetFocusWindow(), SDL_TEXTEDITING, SDL_TEXTINPUT, SDL_VideoDevice::ShowScreenKeyboard, and SDL_VideoDevice::StartTextInput.

Referenced by SDL_VideoInit().

◆ SDL_StopTextInput()

void SDL_StopTextInput ( void  )

Stop receiving any text input events. This function will hide the on-screen keyboard if supported.

See also
SDL_StartTextInput()
SDL_HasScreenKeyboardSupport()

Definition at line 259 of file SDL_dynapi_procs.h.

References _this, SDL_VideoDevice::HideScreenKeyboard, SDL_DISABLE, SDL_EventState, SDL_GetFocusWindow(), SDL_TEXTEDITING, SDL_TEXTINPUT, and SDL_VideoDevice::StopTextInput.