SDL  2.0
SDL_keyboard.c File Reference
#include "../SDL_internal.h"
#include "SDL_timer.h"
#include "SDL_events.h"
#include "SDL_events_c.h"
#include "SDL_assert.h"
#include "../video/SDL_sysvideo.h"
+ Include dependency graph for SDL_keyboard.c:

Go to the source code of this file.

Data Structures

struct  SDL_Keyboard
 

Functions

char * SDL_UCS4ToUTF8 (Uint32 ch, char *dst)
 
int SDL_KeyboardInit (void)
 
void SDL_ResetKeyboard (void)
 
void SDL_GetDefaultKeymap (SDL_Keycode *keymap)
 
void SDL_SetKeymap (int start, SDL_Keycode *keys, int length)
 
void SDL_SetScancodeName (SDL_Scancode scancode, const char *name)
 
SDL_WindowSDL_GetKeyboardFocus (void)
 Get the window which currently has keyboard focus. More...
 
void SDL_SetKeyboardFocus (SDL_Window *window)
 
int SDL_SendKeyboardKey (Uint8 state, SDL_Scancode scancode)
 
int SDL_SendKeyboardText (const char *text)
 
int SDL_SendEditingText (const char *text, int start, int length)
 
void SDL_KeyboardQuit (void)
 
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...
 
void SDL_ToggleModState (const SDL_Keymod modstate, const SDL_bool toggle)
 
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...
 

Variables

static SDL_Keyboard SDL_keyboard
 
static const SDL_Keycode SDL_default_keymap [SDL_NUM_SCANCODES]
 
static const char * SDL_scancode_names [SDL_NUM_SCANCODES]
 

Function Documentation

◆ SDL_GetDefaultKeymap()

void SDL_GetDefaultKeymap ( SDL_Keycode keymap)

Definition at line 588 of file SDL_keyboard.c.

589 {
591 }

References SDL_default_keymap, and SDL_memcpy.

◆ SDL_GetKeyboardFocus()

SDL_Window* SDL_GetKeyboardFocus ( void  )

Get the window which currently has keyboard focus.

Definition at line 622 of file SDL_keyboard.c.

623 {
624  SDL_Keyboard *keyboard = &SDL_keyboard;
625 
626  return keyboard->focus;
627 }

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");
}

Definition at line 837 of file SDL_keyboard.c.

838 {
839  SDL_Keyboard *keyboard = &SDL_keyboard;
840 
841  if (numkeys != (int *) 0) {
842  *numkeys = SDL_NUM_SCANCODES;
843  }
844  return keyboard->keystate;
845 }

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 982 of file SDL_keyboard.c.

983 {
985 
986  /* Check input */
987  if (name == NULL) {
988  return SDLK_UNKNOWN;
989  }
990 
991  /* If it's a single UTF-8 character, then that's the keycode itself */
992  key = *(const unsigned char *)name;
993  if (key >= 0xF0) {
994  if (SDL_strlen(name) == 4) {
995  int i = 0;
996  key = (Uint16)(name[i]&0x07) << 18;
997  key |= (Uint16)(name[++i]&0x3F) << 12;
998  key |= (Uint16)(name[++i]&0x3F) << 6;
999  key |= (Uint16)(name[++i]&0x3F);
1000  return key;
1001  }
1002  return SDLK_UNKNOWN;
1003  } else if (key >= 0xE0) {
1004  if (SDL_strlen(name) == 3) {
1005  int i = 0;
1006  key = (Uint16)(name[i]&0x0F) << 12;
1007  key |= (Uint16)(name[++i]&0x3F) << 6;
1008  key |= (Uint16)(name[++i]&0x3F);
1009  return key;
1010  }
1011  return SDLK_UNKNOWN;
1012  } else if (key >= 0xC0) {
1013  if (SDL_strlen(name) == 2) {
1014  int i = 0;
1015  key = (Uint16)(name[i]&0x1F) << 6;
1016  key |= (Uint16)(name[++i]&0x3F);
1017  return key;
1018  }
1019  return SDLK_UNKNOWN;
1020  } else {
1021  if (SDL_strlen(name) == 1) {
1022  if (key >= 'A' && key <= 'Z') {
1023  key += 32;
1024  }
1025  return key;
1026  }
1027 
1028  /* Get the scancode for this name, and the associated keycode */
1030  }
1031 }

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 877 of file SDL_keyboard.c.

878 {
879  SDL_Keyboard *keyboard = &SDL_keyboard;
880 
881  if (((int)scancode) < ((int)SDL_SCANCODE_UNKNOWN) || scancode >= SDL_NUM_SCANCODES) {
882  SDL_InvalidParamError("scancode");
883  return 0;
884  }
885 
886  return keyboard->keymap[scancode];
887 }

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 943 of file SDL_keyboard.c.

944 {
945  static char name[8];
946  char *end;
947 
948  if (key & SDLK_SCANCODE_MASK) {
949  return
951  }
952 
953  switch (key) {
954  case SDLK_RETURN:
956  case SDLK_ESCAPE:
958  case SDLK_BACKSPACE:
960  case SDLK_TAB:
962  case SDLK_SPACE:
964  case SDLK_DELETE:
966  default:
967  /* Unaccented letter keys on latin keyboards are normally
968  labeled in upper case (and probably on others like Greek or
969  Cyrillic too, so if you happen to know for sure, please
970  adapt this). */
971  if (key >= 'a' && key <= 'z') {
972  key -= 32;
973  }
974 
976  *end = '\0';
977  return name;
978  }
979 }

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 848 of file SDL_keyboard.c.

849 {
850  SDL_Keyboard *keyboard = &SDL_keyboard;
851 
852  return (SDL_Keymod) keyboard->modstate;
853 }

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 890 of file SDL_keyboard.c.

891 {
892  SDL_Keyboard *keyboard = &SDL_keyboard;
893  SDL_Scancode scancode;
894 
895  for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES;
896  ++scancode) {
897  if (keyboard->keymap[scancode] == key) {
898  return scancode;
899  }
900  }
901  return SDL_SCANCODE_UNKNOWN;
902 }

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 920 of file SDL_keyboard.c.

921 {
922  int i;
923 
924  if (!name || !*name) {
925  SDL_InvalidParamError("name");
926  return SDL_SCANCODE_UNKNOWN;
927  }
928 
929  for (i = 0; i < SDL_arraysize(SDL_scancode_names); ++i) {
930  if (!SDL_scancode_names[i]) {
931  continue;
932  }
933  if (SDL_strcasecmp(name, SDL_scancode_names[i]) == 0) {
934  return (SDL_Scancode)i;
935  }
936  }
937 
938  SDL_InvalidParamError("name");
939  return SDL_SCANCODE_UNKNOWN;
940 }

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 905 of file SDL_keyboard.c.

906 {
907  const char *name;
908  if (((int)scancode) < ((int)SDL_SCANCODE_UNKNOWN) || scancode >= SDL_NUM_SCANCODES) {
909  SDL_InvalidParamError("scancode");
910  return "";
911  }
912 
913  name = SDL_scancode_names[scancode];
914  if (name)
915  return name;
916  else
917  return "";
918 }

References SDL_InvalidParamError, SDL_NUM_SCANCODES, SDL_scancode_names, and SDL_SCANCODE_UNKNOWN.

Referenced by SDL_GetKeyName(), and SDL_SendKeyboardKey().

◆ SDL_KeyboardInit()

int SDL_KeyboardInit ( void  )

Definition at line 562 of file SDL_keyboard.c.

563 {
564  SDL_Keyboard *keyboard = &SDL_keyboard;
565 
566  /* Set the default keymap */
568  return (0);
569 }

References SDL_Keyboard::keymap, SDL_default_keymap, SDL_keyboard, and SDL_memcpy.

Referenced by SDL_VideoInit().

◆ SDL_KeyboardQuit()

void SDL_KeyboardQuit ( void  )

Definition at line 832 of file SDL_keyboard.c.

833 {
834 }

Referenced by SDL_VideoQuit().

◆ SDL_ResetKeyboard()

void SDL_ResetKeyboard ( void  )

Definition at line 572 of file SDL_keyboard.c.

573 {
574  SDL_Keyboard *keyboard = &SDL_keyboard;
575  SDL_Scancode scancode;
576 
577 #ifdef DEBUG_KEYBOARD
578  printf("Resetting keyboard\n");
579 #endif
580  for (scancode = (SDL_Scancode) 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
581  if (keyboard->keystate[scancode] == SDL_PRESSED) {
583  }
584  }
585 }

References SDL_Keyboard::keystate, SDL_keyboard, SDL_NUM_SCANCODES, SDL_PRESSED, SDL_RELEASED, and SDL_SendKeyboardKey().

Referenced by SDL_SetKeyboardFocus(), and SDL_ShowMessageBox().

◆ SDL_SendEditingText()

int SDL_SendEditingText ( const char *  text,
int  start,
int  length 
)

Definition at line 812 of file SDL_keyboard.c.

813 {
814  SDL_Keyboard *keyboard = &SDL_keyboard;
815  int posted;
816 
817  /* Post the event, if desired */
818  posted = 0;
821  event.edit.type = SDL_TEXTEDITING;
822  event.edit.windowID = keyboard->focus ? keyboard->focus->id : 0;
823  event.edit.start = start;
824  event.edit.length = length;
825  SDL_utf8strlcpy(event.edit.text, text, SDL_arraysize(event.edit.text));
826  posted = (SDL_PushEvent(&event) > 0);
827  }
828  return (posted);
829 }

References SDL_Keyboard::focus, SDL_Window::id, SDL_arraysize, SDL_ENABLE, SDL_GetEventState, SDL_keyboard, SDL_PushEvent, SDL_TEXTEDITING, SDL_utf8strlcpy, and text.

◆ SDL_SendKeyboardKey()

int SDL_SendKeyboardKey ( Uint8  state,
SDL_Scancode  scancode 
)

Definition at line 679 of file SDL_keyboard.c.

680 {
681  SDL_Keyboard *keyboard = &SDL_keyboard;
682  int posted;
683  SDL_Keymod modifier;
684  SDL_Keycode keycode;
685  Uint32 type;
686  Uint8 repeat;
687 
688  if (!scancode) {
689  return 0;
690  }
691 #ifdef DEBUG_KEYBOARD
692  printf("The '%s' key has been %s\n", SDL_GetScancodeName(scancode),
693  state == SDL_PRESSED ? "pressed" : "released");
694 #endif
695 
696  /* Figure out what type of event this is */
697  switch (state) {
698  case SDL_PRESSED:
699  type = SDL_KEYDOWN;
700  break;
701  case SDL_RELEASED:
702  type = SDL_KEYUP;
703  break;
704  default:
705  /* Invalid state -- bail */
706  return 0;
707  }
708 
709  /* Drop events that don't change state */
710  repeat = (state && keyboard->keystate[scancode]);
711  if (keyboard->keystate[scancode] == state && !repeat) {
712 #if 0
713  printf("Keyboard event didn't change state - dropped!\n");
714 #endif
715  return 0;
716  }
717 
718  /* Update internal keyboard state */
719  keyboard->keystate[scancode] = state;
720 
721  keycode = keyboard->keymap[scancode];
722 
723  /* Update modifiers state if applicable */
724  switch (keycode) {
725  case SDLK_LCTRL:
726  modifier = KMOD_LCTRL;
727  break;
728  case SDLK_RCTRL:
729  modifier = KMOD_RCTRL;
730  break;
731  case SDLK_LSHIFT:
732  modifier = KMOD_LSHIFT;
733  break;
734  case SDLK_RSHIFT:
735  modifier = KMOD_RSHIFT;
736  break;
737  case SDLK_LALT:
738  modifier = KMOD_LALT;
739  break;
740  case SDLK_RALT:
741  modifier = KMOD_RALT;
742  break;
743  case SDLK_LGUI:
744  modifier = KMOD_LGUI;
745  break;
746  case SDLK_RGUI:
747  modifier = KMOD_RGUI;
748  break;
749  case SDLK_MODE:
750  modifier = KMOD_MODE;
751  break;
752  default:
753  modifier = KMOD_NONE;
754  break;
755  }
756  if (SDL_KEYDOWN == type) {
757  switch (keycode) {
758  case SDLK_NUMLOCKCLEAR:
759  keyboard->modstate ^= KMOD_NUM;
760  break;
761  case SDLK_CAPSLOCK:
762  keyboard->modstate ^= KMOD_CAPS;
763  break;
764  default:
765  keyboard->modstate |= modifier;
766  break;
767  }
768  } else {
769  keyboard->modstate &= ~modifier;
770  }
771 
772  /* Post the event, if desired */
773  posted = 0;
776  event.key.type = type;
777  event.key.state = state;
778  event.key.repeat = repeat;
779  event.key.keysym.scancode = scancode;
780  event.key.keysym.sym = keycode;
781  event.key.keysym.mod = keyboard->modstate;
782  event.key.windowID = keyboard->focus ? keyboard->focus->id : 0;
783  posted = (SDL_PushEvent(&event) > 0);
784  }
785  return (posted);
786 }

References SDL_Keyboard::focus, SDL_Window::id, SDL_Keyboard::keymap, SDL_Keyboard::keystate, KMOD_CAPS, KMOD_LALT, KMOD_LCTRL, KMOD_LGUI, KMOD_LSHIFT, KMOD_MODE, KMOD_NONE, KMOD_NUM, KMOD_RALT, KMOD_RCTRL, KMOD_RGUI, KMOD_RSHIFT, SDL_Keyboard::modstate, SDL_ENABLE, SDL_GetEventState, SDL_GetScancodeName(), SDL_keyboard, SDL_KEYDOWN, SDL_KEYUP, SDL_PRESSED, SDL_PushEvent, SDL_RELEASED, SDLK_CAPSLOCK, SDLK_LALT, SDLK_LCTRL, SDLK_LGUI, SDLK_LSHIFT, SDLK_MODE, SDLK_NUMLOCKCLEAR, SDLK_RALT, SDLK_RCTRL, SDLK_RGUI, SDLK_RSHIFT, and state.

Referenced by SDL_BApp::_HandleKey(), handleKeyboardEvent(), SDL_ResetKeyboard(), and WINRT_OnBackButtonPressed().

◆ SDL_SendKeyboardText()

int SDL_SendKeyboardText ( const char *  text)

Definition at line 789 of file SDL_keyboard.c.

790 {
791  SDL_Keyboard *keyboard = &SDL_keyboard;
792  int posted;
793 
794  /* Don't post text events for unprintable characters */
795  if ((unsigned char)*text < ' ' || *text == 127) {
796  return 0;
797  }
798 
799  /* Post the event, if desired */
800  posted = 0;
803  event.text.type = SDL_TEXTINPUT;
804  event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
805  SDL_utf8strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
806  posted = (SDL_PushEvent(&event) > 0);
807  }
808  return (posted);
809 }

References SDL_Keyboard::focus, SDL_Window::id, SDL_arraysize, SDL_ENABLE, SDL_GetEventState, SDL_keyboard, SDL_PushEvent, SDL_TEXTINPUT, SDL_utf8strlcpy, and text.

Referenced by SDL_BApp::_HandleKey().

◆ SDL_SetKeyboardFocus()

void SDL_SetKeyboardFocus ( SDL_Window window)

Definition at line 630 of file SDL_keyboard.c.

631 {
632  SDL_Keyboard *keyboard = &SDL_keyboard;
633 
634  if (keyboard->focus && !window) {
635  /* We won't get anymore keyboard messages, so reset keyboard state */
637  }
638 
639  /* See if the current window has lost focus */
640  if (keyboard->focus && keyboard->focus != window) {
641 
642  /* new window shouldn't think it has mouse captured. */
644 
645  /* old window must lose an existing mouse capture. */
646  if (keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE) {
647  SDL_CaptureMouse(SDL_FALSE); /* drop the capture. */
649  }
650 
652  0, 0);
653 
654  /* Ensures IME compositions are committed */
657  if (video && video->StopTextInput) {
658  video->StopTextInput(video);
659  }
660  }
661  }
662 
663  keyboard->focus = window;
664 
665  if (keyboard->focus) {
667  0, 0);
668 
671  if (video && video->StartTextInput) {
672  video->StartTextInput(video);
673  }
674  }
675  }
676 }

References SDL_Window::flags, SDL_Keyboard::focus, SDL_assert, SDL_CaptureMouse, SDL_EventState, SDL_FALSE, SDL_GetVideoDevice(), SDL_keyboard, SDL_QUERY, SDL_ResetKeyboard(), SDL_SendWindowEvent(), SDL_TEXTINPUT, SDL_WINDOW_MOUSE_CAPTURE, SDL_WINDOWEVENT_FOCUS_GAINED, SDL_WINDOWEVENT_FOCUS_LOST, SDL_VideoDevice::StartTextInput, and SDL_VideoDevice::StopTextInput.

Referenced by SDL_BApp::_HandleKeyboardFocus(), and SDL_DestroyWindow().

◆ SDL_SetKeymap()

void SDL_SetKeymap ( int  start,
SDL_Keycode keys,
int  length 
)

Definition at line 594 of file SDL_keyboard.c.

595 {
596  SDL_Keyboard *keyboard = &SDL_keyboard;
597  SDL_Scancode scancode;
598 
600  return;
601  }
602 
603  SDL_memcpy(&keyboard->keymap[start], keys, sizeof(*keys) * length);
604 
605  /* The number key scancodes always map to the number key keycodes.
606  * On AZERTY layouts these technically are symbols, but users (and games)
607  * always think of them and view them in UI as number keys.
608  */
609  keyboard->keymap[SDL_SCANCODE_0] = SDLK_0;
610  for (scancode = SDL_SCANCODE_1; scancode <= SDL_SCANCODE_9; ++scancode) {
611  keyboard->keymap[scancode] = SDLK_1 + (scancode - SDL_SCANCODE_1);
612  }
613 }

References SDL_Keyboard::keymap, SDL_keyboard, SDL_memcpy, SDL_NUM_SCANCODES, SDL_SCANCODE_0, SDL_SCANCODE_1, SDL_SCANCODE_9, SDLK_0, and SDLK_1.

◆ 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 856 of file SDL_keyboard.c.

857 {
858  SDL_Keyboard *keyboard = &SDL_keyboard;
859 
860  keyboard->modstate = modstate;
861 }

References SDL_Keyboard::modstate, and SDL_keyboard.

◆ SDL_SetScancodeName()

void SDL_SetScancodeName ( SDL_Scancode  scancode,
const char *  name 
)

Definition at line 616 of file SDL_keyboard.c.

617 {
618  SDL_scancode_names[scancode] = name;
619 }

References SDL_scancode_names.

◆ SDL_ToggleModState()

void SDL_ToggleModState ( const SDL_Keymod  modstate,
const SDL_bool  toggle 
)

Definition at line 865 of file SDL_keyboard.c.

866 {
867  SDL_Keyboard *keyboard = &SDL_keyboard;
868  if (toggle) {
869  keyboard->modstate |= modstate;
870  } else {
871  keyboard->modstate &= ~modstate;
872  }
873 }

References SDL_Keyboard::modstate, and SDL_keyboard.

◆ SDL_UCS4ToUTF8()

char* SDL_UCS4ToUTF8 ( Uint32  ch,
char *  dst 
)

Definition at line 520 of file SDL_keyboard.c.

521 {
522  Uint8 *p = (Uint8 *) dst;
523  if (ch <= 0x7F) {
524  *p = (Uint8) ch;
525  ++dst;
526  } else if (ch <= 0x7FF) {
527  p[0] = 0xC0 | (Uint8) ((ch >> 6) & 0x1F);
528  p[1] = 0x80 | (Uint8) (ch & 0x3F);
529  dst += 2;
530  } else if (ch <= 0xFFFF) {
531  p[0] = 0xE0 | (Uint8) ((ch >> 12) & 0x0F);
532  p[1] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
533  p[2] = 0x80 | (Uint8) (ch & 0x3F);
534  dst += 3;
535  } else if (ch <= 0x1FFFFF) {
536  p[0] = 0xF0 | (Uint8) ((ch >> 18) & 0x07);
537  p[1] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
538  p[2] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
539  p[3] = 0x80 | (Uint8) (ch & 0x3F);
540  dst += 4;
541  } else if (ch <= 0x3FFFFFF) {
542  p[0] = 0xF8 | (Uint8) ((ch >> 24) & 0x03);
543  p[1] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
544  p[2] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
545  p[3] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
546  p[4] = 0x80 | (Uint8) (ch & 0x3F);
547  dst += 5;
548  } else {
549  p[0] = 0xFC | (Uint8) ((ch >> 30) & 0x01);
550  p[1] = 0x80 | (Uint8) ((ch >> 24) & 0x3F);
551  p[2] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
552  p[3] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
553  p[4] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
554  p[5] = 0x80 | (Uint8) (ch & 0x3F);
555  dst += 6;
556  }
557  return dst;
558 }

Referenced by SDL_GetKeyName().

Variable Documentation

◆ SDL_default_keymap

const SDL_Keycode SDL_default_keymap[SDL_NUM_SCANCODES]
static

Definition at line 49 of file SDL_keyboard.c.

Referenced by SDL_GetDefaultKeymap(), SDL_GetKeyFromName(), and SDL_KeyboardInit().

◆ SDL_keyboard

◆ SDL_scancode_names

const char* SDL_scancode_names[SDL_NUM_SCANCODES]
static
SDL_WINDOW_MOUSE_CAPTURE
@ SDL_WINDOW_MOUSE_CAPTURE
Definition: SDL_video.h:116
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
SDL_Keyboard::modstate
Uint16 modstate
Definition: SDL_keyboard.c:42
SDLK_UNKNOWN
@ SDLK_UNKNOWN
Definition: SDL_keycode.h:52
SDLK_RALT
@ SDLK_RALT
Definition: SDL_keycode.h:282
SDL_scancode_names
static const char * SDL_scancode_names[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:282
end
GLuint GLuint end
Definition: SDL_opengl.h:1571
KMOD_LALT
@ KMOD_LALT
Definition: SDL_keycode.h:332
KMOD_LGUI
@ KMOD_LGUI
Definition: SDL_keycode.h:334
NULL
#define NULL
Definition: begin_code.h:167
SDLK_LSHIFT
@ SDLK_LSHIFT
Definition: SDL_keycode.h:277
SDL_WINDOWEVENT_FOCUS_LOST
@ SDL_WINDOWEVENT_FOCUS_LOST
Definition: SDL_video.h:166
SDL_Keyboard::keystate
Uint8 keystate[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:43
SDL_KEYUP
@ SDL_KEYUP
Definition: SDL_events.h:97
SDLK_NUMLOCKCLEAR
@ SDLK_NUMLOCKCLEAR
Definition: SDL_keycode.h:156
KMOD_NUM
@ KMOD_NUM
Definition: SDL_keycode.h:336
SDL_UCS4ToUTF8
char * SDL_UCS4ToUTF8(Uint32 ch, char *dst)
Definition: SDL_keyboard.c:520
SDL_Scancode
SDL_Scancode
The SDL keyboard scancode representation.
Definition: SDL_scancode.h:43
SDL_InvalidParamError
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
SDL_TEXTEDITING
@ SDL_TEXTEDITING
Definition: SDL_events.h:98
SDL_SCANCODE_TAB
@ SDL_SCANCODE_TAB
Definition: SDL_scancode.h:95
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:759
SDL_utf8strlcpy
#define SDL_utf8strlcpy
Definition: SDL_dynapi_overrides.h:395
SDL_RELEASED
#define SDL_RELEASED
Definition: SDL_events.h:49
SDL_KEYDOWN
@ SDL_KEYDOWN
Definition: SDL_events.h:96
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
length
GLuint GLsizei GLsizei * length
Definition: SDL_opengl_glext.h:669
SDL_SendKeyboardKey
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:679
KMOD_RALT
@ KMOD_RALT
Definition: SDL_keycode.h:333
SDL_strcasecmp
#define SDL_strcasecmp
Definition: SDL_dynapi_overrides.h:419
SDL_ResetKeyboard
void SDL_ResetKeyboard(void)
Definition: SDL_keyboard.c:572
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1737
SDLK_LGUI
@ SDLK_LGUI
Definition: SDL_keycode.h:279
SDLK_ESCAPE
@ SDLK_ESCAPE
Definition: SDL_keycode.h:55
SDL_QUERY
#define SDL_QUERY
Definition: SDL_events.h:756
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:387
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
SDL_Keyboard
Definition: SDL_keyboard.c:38
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
SDL_SCANCODE_SPACE
@ SDL_SCANCODE_SPACE
Definition: SDL_scancode.h:96
SDL_SCANCODE_9
@ SDL_SCANCODE_9
Definition: SDL_scancode.h:89
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:772
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_TEXTINPUT
@ SDL_TEXTINPUT
Definition: SDL_events.h:99
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:125
SDL_default_keymap
static const SDL_Keycode SDL_default_keymap[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:49
SDL_Keyboard::keymap
SDL_Keycode keymap[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:44
SDL_GetKeyboardState
#define SDL_GetKeyboardState
Definition: SDL_dynapi_overrides.h:217
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
SDLK_SPACE
@ SDLK_SPACE
Definition: SDL_keycode.h:58
KMOD_LCTRL
@ KMOD_LCTRL
Definition: SDL_keycode.h:330
SDL_SCANCODE_0
@ SDL_SCANCODE_0
Definition: SDL_scancode.h:90
SDL_SCANCODE_ESCAPE
@ SDL_SCANCODE_ESCAPE
Definition: SDL_scancode.h:93
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:191
key
GLuint64 key
Definition: gl2ext.h:2192
SDL_VideoDevice::StartTextInput
void(* StartTextInput)(_THIS)
Definition: SDL_sysvideo.h:287
SDLK_MODE
@ SDLK_MODE
Definition: SDL_keycode.h:285
SDL_SCANCODE_BACKSPACE
@ SDL_SCANCODE_BACKSPACE
Definition: SDL_scancode.h:94
KMOD_RSHIFT
@ KMOD_RSHIFT
Definition: SDL_keycode.h:329
text
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47
SDL_VideoDevice::StopTextInput
void(* StopTextInput)(_THIS)
Definition: SDL_sysvideo.h:288
SDLK_0
@ SDLK_0
Definition: SDL_keycode.h:74
KMOD_RCTRL
@ KMOD_RCTRL
Definition: SDL_keycode.h:331
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:169
SDL_GetScancodeName
const char * SDL_GetScancodeName(SDL_Scancode scancode)
Get a human-readable name for a scancode.
Definition: SDL_keyboard.c:905
start
GLuint start
Definition: SDL_opengl.h:1571
SDLK_BACKSPACE
@ SDLK_BACKSPACE
Definition: SDL_keycode.h:56
SDL_VideoDevice
Definition: SDL_sysvideo.h:148
SDL_Keyboard::focus
SDL_Window * focus
Definition: SDL_keyboard.c:41
SDLK_SCANCODE_MASK
#define SDLK_SCANCODE_MASK
Definition: SDL_keycode.h:47
SDL_SCANCODE_UNKNOWN
@ SDL_SCANCODE_UNKNOWN
Definition: SDL_scancode.h:45
SDLK_DELETE
@ SDLK_DELETE
Definition: SDL_keycode.h:148
SDL_arraysize
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
SDL_SCANCODE_DELETE
@ SDL_SCANCODE_DELETE
Definition: SDL_scancode.h:173
SDLK_RGUI
@ SDLK_RGUI
Definition: SDL_keycode.h:283
SDLK_RCTRL
@ SDLK_RCTRL
Definition: SDL_keycode.h:280
SDLK_RETURN
@ SDLK_RETURN
Definition: SDL_keycode.h:54
KMOD_LSHIFT
@ KMOD_LSHIFT
Definition: SDL_keycode.h:328
KMOD_RGUI
@ KMOD_RGUI
Definition: SDL_keycode.h:335
SDL_Window::id
Uint32 id
Definition: SDL_sysvideo.h:76
SDLK_RSHIFT
@ SDLK_RSHIFT
Definition: SDL_keycode.h:281
SDLK_TAB
@ SDLK_TAB
Definition: SDL_keycode.h:57
SDL_EventState
#define SDL_EventState
Definition: SDL_dynapi_overrides.h:131
SDL_SendWindowEvent
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
Definition: SDL_windowevents.c:74
SDL_strlen
#define SDL_strlen
Definition: SDL_dynapi_overrides.h:393
SDL_CaptureMouse
#define SDL_CaptureMouse
Definition: SDL_dynapi_overrides.h:584
SDL_NUM_SCANCODES
@ SDL_NUM_SCANCODES
Definition: SDL_scancode.h:407
SDL_SCANCODE_1
@ SDL_SCANCODE_1
Definition: SDL_scancode.h:81
SDL_Event
General event structure.
Definition: SDL_events.h:557
SDL_GetVideoDevice
SDL_VideoDevice * SDL_GetVideoDevice(void)
Definition: SDL_video.c:583
SDLK_CAPSLOCK
@ SDLK_CAPSLOCK
Definition: SDL_keycode.h:127
SDL_WINDOWEVENT_FOCUS_GAINED
@ SDL_WINDOWEVENT_FOCUS_GAINED
Definition: SDL_video.h:165
SDLK_LALT
@ SDLK_LALT
Definition: SDL_keycode.h:278
SDL_Window::flags
Uint32 flags
Definition: SDL_sysvideo.h:83
type
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1571
state
struct xkb_state * state
Definition: SDL_waylandsym.h:113
SDLK_LCTRL
@ SDLK_LCTRL
Definition: SDL_keycode.h:276
KMOD_MODE
@ KMOD_MODE
Definition: SDL_keycode.h:338
i
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
KMOD_CAPS
@ KMOD_CAPS
Definition: SDL_keycode.h:337
SDLK_1
@ SDLK_1
Definition: SDL_keycode.h:75
SDL_GetScancodeFromName
SDL_Scancode SDL_GetScancodeFromName(const char *name)
Get a scancode from a human-readable name.
Definition: SDL_keyboard.c:920
KMOD_NONE
@ KMOD_NONE
Definition: SDL_keycode.h:327
SDL_SCANCODE_RETURN
@ SDL_SCANCODE_RETURN
Definition: SDL_scancode.h:92
SDL_keyboard
static SDL_Keyboard SDL_keyboard
Definition: SDL_keyboard.c:47
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:179