zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_keyboard.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2013 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 #include "SDL_config.h"
22 
23 /* General keyboard handling code for SDL */
24 
25 #include "SDL_timer.h"
26 #include "SDL_events.h"
27 #include "SDL_events_c.h"
28 #include "../video/SDL_sysvideo.h"
29 
30 
31 /* #define DEBUG_KEYBOARD */
32 
33 /* Global keyboard information */
34 
35 typedef struct SDL_Keyboard SDL_Keyboard;
36 
37 struct SDL_Keyboard
38 {
39  /* Data common to all keyboards */
40  SDL_Window *focus;
41  Uint16 modstate;
42  Uint8 keystate[SDL_NUM_SCANCODES];
44 };
45 
47 
49  0, 0, 0, 0,
50  'a',
51  'b',
52  'c',
53  'd',
54  'e',
55  'f',
56  'g',
57  'h',
58  'i',
59  'j',
60  'k',
61  'l',
62  'm',
63  'n',
64  'o',
65  'p',
66  'q',
67  'r',
68  's',
69  't',
70  'u',
71  'v',
72  'w',
73  'x',
74  'y',
75  'z',
76  '1',
77  '2',
78  '3',
79  '4',
80  '5',
81  '6',
82  '7',
83  '8',
84  '9',
85  '0',
89  SDLK_TAB,
90  SDLK_SPACE,
91  '-',
92  '=',
93  '[',
94  ']',
95  '\\',
96  '#',
97  ';',
98  '\'',
99  '`',
100  ',',
101  '.',
102  '/',
104  SDLK_F1,
105  SDLK_F2,
106  SDLK_F3,
107  SDLK_F4,
108  SDLK_F5,
109  SDLK_F6,
110  SDLK_F7,
111  SDLK_F8,
112  SDLK_F9,
113  SDLK_F10,
114  SDLK_F11,
115  SDLK_F12,
118  SDLK_PAUSE,
119  SDLK_INSERT,
120  SDLK_HOME,
121  SDLK_PAGEUP,
122  SDLK_DELETE,
123  SDLK_END,
125  SDLK_RIGHT,
126  SDLK_LEFT,
127  SDLK_DOWN,
128  SDLK_UP,
133  SDLK_KP_PLUS,
135  SDLK_KP_1,
136  SDLK_KP_2,
137  SDLK_KP_3,
138  SDLK_KP_4,
139  SDLK_KP_5,
140  SDLK_KP_6,
141  SDLK_KP_7,
142  SDLK_KP_8,
143  SDLK_KP_9,
144  SDLK_KP_0,
146  0,
148  SDLK_POWER,
150  SDLK_F13,
151  SDLK_F14,
152  SDLK_F15,
153  SDLK_F16,
154  SDLK_F17,
155  SDLK_F18,
156  SDLK_F19,
157  SDLK_F20,
158  SDLK_F21,
159  SDLK_F22,
160  SDLK_F23,
161  SDLK_F24,
162  SDLK_EXECUTE,
163  SDLK_HELP,
164  SDLK_MENU,
165  SDLK_SELECT,
166  SDLK_STOP,
167  SDLK_AGAIN,
168  SDLK_UNDO,
169  SDLK_CUT,
170  SDLK_COPY,
171  SDLK_PASTE,
172  SDLK_FIND,
173  SDLK_MUTE,
176  0, 0, 0,
179  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
181  SDLK_SYSREQ,
182  SDLK_CANCEL,
183  SDLK_CLEAR,
184  SDLK_PRIOR,
185  SDLK_RETURN2,
187  SDLK_OUT,
188  SDLK_OPER,
190  SDLK_CRSEL,
191  SDLK_EXSEL,
192  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
193  SDLK_KP_00,
194  SDLK_KP_000,
203  SDLK_KP_TAB,
205  SDLK_KP_A,
206  SDLK_KP_B,
207  SDLK_KP_C,
208  SDLK_KP_D,
209  SDLK_KP_E,
210  SDLK_KP_F,
211  SDLK_KP_XOR,
214  SDLK_KP_LESS,
221  SDLK_KP_HASH,
223  SDLK_KP_AT,
239  0, 0,
240  SDLK_LCTRL,
241  SDLK_LSHIFT,
242  SDLK_LALT,
243  SDLK_LGUI,
244  SDLK_RCTRL,
245  SDLK_RSHIFT,
246  SDLK_RALT,
247  SDLK_RGUI,
248  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
249  SDLK_MODE,
256  SDLK_WWW,
257  SDLK_MAIL,
261  SDLK_AC_HOME,
262  SDLK_AC_BACK,
264  SDLK_AC_STOP,
273  SDLK_EJECT,
274  SDLK_SLEEP,
275 };
276 
277 static const char *SDL_scancode_names[SDL_NUM_SCANCODES] = {
278  NULL, NULL, NULL, NULL,
279  "A",
280  "B",
281  "C",
282  "D",
283  "E",
284  "F",
285  "G",
286  "H",
287  "I",
288  "J",
289  "K",
290  "L",
291  "M",
292  "N",
293  "O",
294  "P",
295  "Q",
296  "R",
297  "S",
298  "T",
299  "U",
300  "V",
301  "W",
302  "X",
303  "Y",
304  "Z",
305  "1",
306  "2",
307  "3",
308  "4",
309  "5",
310  "6",
311  "7",
312  "8",
313  "9",
314  "0",
315  "Return",
316  "Escape",
317  "Backspace",
318  "Tab",
319  "Space",
320  "-",
321  "=",
322  "[",
323  "]",
324  "\\",
325  "#",
326  ";",
327  "'",
328  "`",
329  ",",
330  ".",
331  "/",
332  "CapsLock",
333  "F1",
334  "F2",
335  "F3",
336  "F4",
337  "F5",
338  "F6",
339  "F7",
340  "F8",
341  "F9",
342  "F10",
343  "F11",
344  "F12",
345  "PrintScreen",
346  "ScrollLock",
347  "Pause",
348  "Insert",
349  "Home",
350  "PageUp",
351  "Delete",
352  "End",
353  "PageDown",
354  "Right",
355  "Left",
356  "Down",
357  "Up",
358  "Numlock",
359  "Keypad /",
360  "Keypad *",
361  "Keypad -",
362  "Keypad +",
363  "Keypad Enter",
364  "Keypad 1",
365  "Keypad 2",
366  "Keypad 3",
367  "Keypad 4",
368  "Keypad 5",
369  "Keypad 6",
370  "Keypad 7",
371  "Keypad 8",
372  "Keypad 9",
373  "Keypad 0",
374  "Keypad .",
375  NULL,
376  "Application",
377  "Power",
378  "Keypad =",
379  "F13",
380  "F14",
381  "F15",
382  "F16",
383  "F17",
384  "F18",
385  "F19",
386  "F20",
387  "F21",
388  "F22",
389  "F23",
390  "F24",
391  "Execute",
392  "Help",
393  "Menu",
394  "Select",
395  "Stop",
396  "Again",
397  "Undo",
398  "Cut",
399  "Copy",
400  "Paste",
401  "Find",
402  "Mute",
403  "VolumeUp",
404  "VolumeDown",
405  NULL, NULL, NULL,
406  "Keypad ,",
407  "Keypad = (AS400)",
409  NULL, NULL, NULL, NULL, NULL, NULL,
410  "AltErase",
411  "SysReq",
412  "Cancel",
413  "Clear",
414  "Prior",
415  "Return",
416  "Separator",
417  "Out",
418  "Oper",
419  "Clear / Again",
420  "CrSel",
421  "ExSel",
423  "Keypad 00",
424  "Keypad 000",
425  "ThousandsSeparator",
426  "DecimalSeparator",
427  "CurrencyUnit",
428  "CurrencySubUnit",
429  "Keypad (",
430  "Keypad )",
431  "Keypad {",
432  "Keypad }",
433  "Keypad Tab",
434  "Keypad Backspace",
435  "Keypad A",
436  "Keypad B",
437  "Keypad C",
438  "Keypad D",
439  "Keypad E",
440  "Keypad F",
441  "Keypad XOR",
442  "Keypad ^",
443  "Keypad %",
444  "Keypad <",
445  "Keypad >",
446  "Keypad &",
447  "Keypad &&",
448  "Keypad |",
449  "Keypad ||",
450  "Keypad :",
451  "Keypad #",
452  "Keypad Space",
453  "Keypad @",
454  "Keypad !",
455  "Keypad MemStore",
456  "Keypad MemRecall",
457  "Keypad MemClear",
458  "Keypad MemAdd",
459  "Keypad MemSubtract",
460  "Keypad MemMultiply",
461  "Keypad MemDivide",
462  "Keypad +/-",
463  "Keypad Clear",
464  "Keypad ClearEntry",
465  "Keypad Binary",
466  "Keypad Octal",
467  "Keypad Decimal",
468  "Keypad Hexadecimal",
469  NULL, NULL,
470  "Left Ctrl",
471  "Left Shift",
472  "Left Alt",
473  "Left GUI",
474  "Right Ctrl",
475  "Right Shift",
476  "Right Alt",
477  "Right GUI",
480  NULL,
481  "ModeSwitch",
482  "AudioNext",
483  "AudioPrev",
484  "AudioStop",
485  "AudioPlay",
486  "AudioMute",
487  "MediaSelect",
488  "WWW",
489  "Mail",
490  "Calculator",
491  "Computer",
492  "AC Search",
493  "AC Home",
494  "AC Back",
495  "AC Forward",
496  "AC Stop",
497  "AC Refresh",
498  "AC Bookmarks",
499  "BrightnessDown",
500  "BrightnessUp",
501  "DisplaySwitch",
502  "KBDIllumToggle",
503  "KBDIllumDown",
504  "KBDIllumUp",
505  "Eject",
506  "Sleep",
507 };
508 
509 /* Taken from SDL_iconv() */
510 static char *
512 {
513  Uint8 *p = (Uint8 *) dst;
514  if (ch <= 0x7F) {
515  *p = (Uint8) ch;
516  ++dst;
517  } else if (ch <= 0x7FF) {
518  p[0] = 0xC0 | (Uint8) ((ch >> 6) & 0x1F);
519  p[1] = 0x80 | (Uint8) (ch & 0x3F);
520  dst += 2;
521  } else if (ch <= 0xFFFF) {
522  p[0] = 0xE0 | (Uint8) ((ch >> 12) & 0x0F);
523  p[1] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
524  p[2] = 0x80 | (Uint8) (ch & 0x3F);
525  dst += 3;
526  } else if (ch <= 0x1FFFFF) {
527  p[0] = 0xF0 | (Uint8) ((ch >> 18) & 0x07);
528  p[1] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
529  p[2] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
530  p[3] = 0x80 | (Uint8) (ch & 0x3F);
531  dst += 4;
532  } else if (ch <= 0x3FFFFFF) {
533  p[0] = 0xF8 | (Uint8) ((ch >> 24) & 0x03);
534  p[1] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
535  p[2] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
536  p[3] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
537  p[4] = 0x80 | (Uint8) (ch & 0x3F);
538  dst += 5;
539  } else {
540  p[0] = 0xFC | (Uint8) ((ch >> 30) & 0x01);
541  p[1] = 0x80 | (Uint8) ((ch >> 24) & 0x3F);
542  p[2] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
543  p[3] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
544  p[4] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
545  p[5] = 0x80 | (Uint8) (ch & 0x3F);
546  dst += 6;
547  }
548  return dst;
549 }
550 
551 /* Public functions */
552 int
554 {
555  SDL_Keyboard *keyboard = &SDL_keyboard;
556 
557  /* Set the default keymap */
558  SDL_memcpy(keyboard->keymap, SDL_default_keymap, sizeof(SDL_default_keymap));
559  return (0);
560 }
561 
562 void
564 {
565  SDL_Keyboard *keyboard = &SDL_keyboard;
566  SDL_Scancode scancode;
567 
568 #ifdef DEBUG_KEYBOARD
569  printf("Resetting keyboard\n");
570 #endif
571  for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
572  if (keyboard->keystate[scancode] == SDL_PRESSED) {
574  }
575  }
576 }
577 
578 void
580 {
582 }
583 
584 void
586 {
587  SDL_Keyboard *keyboard = &SDL_keyboard;
588 
590  return;
591  }
592 
593  SDL_memcpy(&keyboard->keymap[start], keys, sizeof(*keys) * length);
594 }
595 
596 void
597 SDL_SetScancodeName(SDL_Scancode scancode, const char *name)
598 {
599  SDL_scancode_names[scancode] = name;
600 }
601 
602 SDL_Window *
604 {
605  SDL_Keyboard *keyboard = &SDL_keyboard;
606 
607  return keyboard->focus;
608 }
609 
610 void
612 {
613  SDL_Keyboard *keyboard = &SDL_keyboard;
614 
615  if (keyboard->focus && !window) {
616  /* We won't get anymore keyboard messages, so reset keyboard state */
618  }
619 
620  /* See if the current window has lost focus */
621  if (keyboard->focus && keyboard->focus != window) {
623  0, 0);
624 
625  /* Ensures IME compositions are committed */
628  if (video && video->StopTextInput) {
629  video->StopTextInput(video);
630  }
631  }
632  }
633 
634  keyboard->focus = window;
635 
636  if (keyboard->focus) {
638  0, 0);
639 
642  if (video && video->StartTextInput) {
643  video->StartTextInput(video);
644  }
645  }
646  }
647 }
648 
649 int
651 {
652  SDL_Keyboard *keyboard = &SDL_keyboard;
653  int posted;
654  Uint16 modstate;
655  Uint32 type;
656  Uint8 repeat;
657 
658  if (!scancode) {
659  return 0;
660  }
661 #ifdef DEBUG_KEYBOARD
662  printf("The '%s' key has been %s\n", SDL_GetScancodeName(scancode),
663  state == SDL_PRESSED ? "pressed" : "released");
664 #endif
665  if (state == SDL_PRESSED) {
666  modstate = keyboard->modstate;
667  switch (scancode) {
669  keyboard->modstate ^= KMOD_NUM;
670  break;
672  keyboard->modstate ^= KMOD_CAPS;
673  break;
674  case SDL_SCANCODE_LCTRL:
675  keyboard->modstate |= KMOD_LCTRL;
676  break;
677  case SDL_SCANCODE_RCTRL:
678  keyboard->modstate |= KMOD_RCTRL;
679  break;
680  case SDL_SCANCODE_LSHIFT:
681  keyboard->modstate |= KMOD_LSHIFT;
682  break;
683  case SDL_SCANCODE_RSHIFT:
684  keyboard->modstate |= KMOD_RSHIFT;
685  break;
686  case SDL_SCANCODE_LALT:
687  keyboard->modstate |= KMOD_LALT;
688  break;
689  case SDL_SCANCODE_RALT:
690  keyboard->modstate |= KMOD_RALT;
691  break;
692  case SDL_SCANCODE_LGUI:
693  keyboard->modstate |= KMOD_LGUI;
694  break;
695  case SDL_SCANCODE_RGUI:
696  keyboard->modstate |= KMOD_RGUI;
697  break;
698  case SDL_SCANCODE_MODE:
699  keyboard->modstate |= KMOD_MODE;
700  break;
701  default:
702  break;
703  }
704  } else {
705  switch (scancode) {
708  break;
709  case SDL_SCANCODE_LCTRL:
710  keyboard->modstate &= ~KMOD_LCTRL;
711  break;
712  case SDL_SCANCODE_RCTRL:
713  keyboard->modstate &= ~KMOD_RCTRL;
714  break;
715  case SDL_SCANCODE_LSHIFT:
716  keyboard->modstate &= ~KMOD_LSHIFT;
717  break;
718  case SDL_SCANCODE_RSHIFT:
719  keyboard->modstate &= ~KMOD_RSHIFT;
720  break;
721  case SDL_SCANCODE_LALT:
722  keyboard->modstate &= ~KMOD_LALT;
723  break;
724  case SDL_SCANCODE_RALT:
725  keyboard->modstate &= ~KMOD_RALT;
726  break;
727  case SDL_SCANCODE_LGUI:
728  keyboard->modstate &= ~KMOD_LGUI;
729  break;
730  case SDL_SCANCODE_RGUI:
731  keyboard->modstate &= ~KMOD_RGUI;
732  break;
733  case SDL_SCANCODE_MODE:
734  keyboard->modstate &= ~KMOD_MODE;
735  break;
736  default:
737  break;
738  }
739  modstate = keyboard->modstate;
740  }
741 
742  /* Figure out what type of event this is */
743  switch (state) {
744  case SDL_PRESSED:
745  type = SDL_KEYDOWN;
746  break;
747  case SDL_RELEASED:
748  type = SDL_KEYUP;
749  break;
750  default:
751  /* Invalid state -- bail */
752  return 0;
753  }
754 
755  /* Drop events that don't change state */
756  repeat = (state && keyboard->keystate[scancode]);
757  if (keyboard->keystate[scancode] == state && !repeat) {
758 #if 0
759  printf("Keyboard event didn't change state - dropped!\n");
760 #endif
761  return 0;
762  }
763 
764  /* Update internal keyboard state */
765  keyboard->keystate[scancode] = state;
766 
767  /* Post the event, if desired */
768  posted = 0;
769  if (SDL_GetEventState(type) == SDL_ENABLE) {
771  event.key.type = type;
772  event.key.state = state;
773  event.key.repeat = repeat;
774  event.key.keysym.scancode = scancode;
775  event.key.keysym.sym = keyboard->keymap[scancode];
776  event.key.keysym.mod = modstate;
777  event.key.windowID = keyboard->focus ? keyboard->focus->id : 0;
778  posted = (SDL_PushEvent(&event) > 0);
779  }
780  return (posted);
781 }
782 
783 int
784 SDL_SendKeyboardText(const char *text)
785 {
786  SDL_Keyboard *keyboard = &SDL_keyboard;
787  int posted;
788 
789  /* Don't post text events for unprintable characters */
790  if ((unsigned char)*text < ' ' || *text == 127) {
791  return 0;
792  }
793 
794  /* Post the event, if desired */
795  posted = 0;
798  event.text.type = SDL_TEXTINPUT;
799  event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
800  SDL_utf8strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
801  posted = (SDL_PushEvent(&event) > 0);
802  }
803  return (posted);
804 }
805 
806 int
807 SDL_SendEditingText(const char *text, int start, int length)
808 {
809  SDL_Keyboard *keyboard = &SDL_keyboard;
810  int posted;
811 
812  /* Post the event, if desired */
813  posted = 0;
816  event.edit.type = SDL_TEXTEDITING;
817  event.edit.windowID = keyboard->focus ? keyboard->focus->id : 0;
818  event.edit.start = start;
819  event.edit.length = length;
820  SDL_utf8strlcpy(event.edit.text, text, SDL_arraysize(event.edit.text));
821  posted = (SDL_PushEvent(&event) > 0);
822  }
823  return (posted);
824 }
825 
826 void
828 {
829 }
830 
831 const Uint8 *
832 SDL_GetKeyboardState(int *numkeys)
833 {
834  SDL_Keyboard *keyboard = &SDL_keyboard;
835 
836  if (numkeys != (int *) 0) {
837  *numkeys = SDL_NUM_SCANCODES;
838  }
839  return keyboard->keystate;
840 }
841 
844 {
845  SDL_Keyboard *keyboard = &SDL_keyboard;
846 
847  return keyboard->modstate;
848 }
849 
850 void
852 {
853  SDL_Keyboard *keyboard = &SDL_keyboard;
854 
855  keyboard->modstate = modstate;
856 }
857 
860 {
861  SDL_Keyboard *keyboard = &SDL_keyboard;
862 
863  if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
864  SDL_InvalidParamError("scancode");
865  return 0;
866  }
867 
868  return keyboard->keymap[scancode];
869 }
870 
873 {
874  SDL_Keyboard *keyboard = &SDL_keyboard;
875  SDL_Scancode scancode;
876 
877  for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES;
878  ++scancode) {
879  if (keyboard->keymap[scancode] == key) {
880  return scancode;
881  }
882  }
883  return SDL_SCANCODE_UNKNOWN;
884 }
885 
886 const char *
888 {
889  const char *name;
890  if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
891  SDL_InvalidParamError("scancode");
892  return "";
893  }
894 
895  name = SDL_scancode_names[scancode];
896  if (name)
897  return name;
898  else
899  return "";
900 }
901 
903 {
904  int i;
905 
906  if (!name || !*name) {
907  SDL_InvalidParamError("name");
908  return SDL_SCANCODE_UNKNOWN;
909  }
910 
911  for (i = 0; i < SDL_arraysize(SDL_scancode_names); ++i) {
912  if (!SDL_scancode_names[i]) {
913  continue;
914  }
915  if (SDL_strcasecmp(name, SDL_scancode_names[i]) == 0) {
916  return (SDL_Scancode)i;
917  }
918  }
919 
920  SDL_InvalidParamError("name");
921  return SDL_SCANCODE_UNKNOWN;
922 }
923 
924 const char *
926 {
927  static char name[8];
928  char *end;
929 
930  if (key & SDLK_SCANCODE_MASK) {
931  return
932  SDL_GetScancodeName((SDL_Scancode) (key & ~SDLK_SCANCODE_MASK));
933  }
934 
935  switch (key) {
936  case SDLK_RETURN:
938  case SDLK_ESCAPE:
940  case SDLK_BACKSPACE:
942  case SDLK_TAB:
944  case SDLK_SPACE:
946  case SDLK_DELETE:
948  default:
949  /* Unaccented letter keys on latin keyboards are normally
950  labeled in upper case (and probably on others like Greek or
951  Cyrillic too, so if you happen to know for sure, please
952  adapt this). */
953  if (key >= 'a' && key <= 'z') {
954  key -= 32;
955  }
956 
957  end = SDL_UCS4ToUTF8((Uint32) key, name);
958  *end = '\0';
959  return name;
960  }
961 }
962 
965 {
966  SDL_Keycode key;
967 
968  /* Check input */
969  if (name == NULL) return SDLK_UNKNOWN;
970 
971  /* If it's a single UTF-8 character, then that's the keycode itself */
972  key = *(const unsigned char *)name;
973  if (key >= 0xF0) {
974  if (SDL_strlen(name) == 4) {
975  int i = 0;
976  key = (Uint16)(name[i]&0x07) << 18;
977  key |= (Uint16)(name[++i]&0x3F) << 12;
978  key |= (Uint16)(name[++i]&0x3F) << 6;
979  key |= (Uint16)(name[++i]&0x3F);
980  return key;
981  }
982  return SDLK_UNKNOWN;
983  } else if (key >= 0xE0) {
984  if (SDL_strlen(name) == 3) {
985  int i = 0;
986  key = (Uint16)(name[i]&0x0F) << 12;
987  key |= (Uint16)(name[++i]&0x3F) << 6;
988  key |= (Uint16)(name[++i]&0x3F);
989  return key;
990  }
991  return SDLK_UNKNOWN;
992  } else if (key >= 0xC0) {
993  if (SDL_strlen(name) == 2) {
994  int i = 0;
995  key = (Uint16)(name[i]&0x1F) << 6;
996  key |= (Uint16)(name[++i]&0x3F);
997  return key;
998  }
999  return SDLK_UNKNOWN;
1000  } else {
1001  if (SDL_strlen(name) == 1) {
1002  if (key >= 'A' && key <= 'Z') {
1003  key += 32;
1004  }
1005  return key;
1006  }
1007 
1008  /* Get the scancode for this name, and the associated keycode */
1010  }
1011 }
1012 
1013 /* vi: set ts=4 sw=4 expandtab: */
void SDL_GetDefaultKeymap(SDL_Keycode *keymap)
Definition: SDL_keyboard.c:579
DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event *event)
Add an event to the event queue.
Definition: SDL_events.c:457
DECLSPEC const char *SDLCALL SDL_GetKeyName(SDL_Keycode key)
Get a human-readable name for a key.
Definition: SDL_keyboard.c:925
void SDL_SetKeyboardFocus(SDL_Window *window)
Definition: SDL_keyboard.c:611
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
#define NULL
Definition: ftobjs.h:61
GLuint start
Definition: glew.h:1239
DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *name)
Get a scancode from a human-readable name.
Definition: SDL_keyboard.c:902
void(* StopTextInput)(_THIS)
Definition: SDL_sysvideo.h:244
struct SDL_Keyboard SDL_Keyboard
Definition: SDL_keyboard.c:35
#define SDL_ENABLE
Definition: SDL_events.h:688
#define SDLK_SCANCODE_MASK
Definition: SDL_keycode.h:44
DECLSPEC const Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys)
Get a snapshot of the current state of the keyboard.
Definition: SDL_keyboard.c:832
EGLImageKHR EGLint * name
Definition: eglext.h:284
DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state)
Definition: SDL_events.c:555
DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes)
Definition: SDL_string.c:463
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
int SDL_KeyboardInit(void)
Definition: SDL_keyboard.c:553
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
Sint32 SDL_Keycode
The SDL virtual key representation.
Definition: SDL_keycode.h:42
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:650
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:145
void SDL_SetKeymap(int start, SDL_Keycode *keys, int length)
Definition: SDL_keyboard.c:585
static const char * SDL_scancode_names[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:277
DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromScancode(SDL_Scancode scancode)
Get the key code corresponding to the given scancode according to the current keyboard layout...
Definition: SDL_keyboard.c:859
SDL_TextInputEvent text
Definition: SDL_events.h:502
char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]
Definition: SDL_events.h:212
GLenum GLenum dst
Definition: glew.h:2396
#define SDL_GetEventState(type)
Definition: SDL_events.h:701
GLsizei GLsizei * length
Definition: gl2ext.h:792
int SDL_SendKeyboardText(const char *text)
Definition: SDL_keyboard.c:784
GLfloat GLfloat p
Definition: glew.h:14938
static const SDL_Keycode SDL_default_keymap[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:48
char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]
Definition: SDL_events.h:197
DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key)
Get the scancode corresponding to the given key code according to the current keyboard layout...
Definition: SDL_keyboard.c:872
DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name)
Get a key code from a human-readable name.
Definition: SDL_keyboard.c:964
void SDL_SetScancodeName(SDL_Scancode scancode, const char *name)
Definition: SDL_keyboard.c:597
DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_Scancode scancode)
Get a human-readable name for a scancode.
Definition: SDL_keyboard.c:887
void SDL_KeyboardQuit(void)
Definition: SDL_keyboard.c:827
SDL_Keymod
Enumeration of valid key mods (possibly OR&#39;d together).
Definition: SDL_keycode.h:317
DECLSPEC size_t SDLCALL SDL_strlen(const char *str)
Definition: SDL_string.c:389
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:83
SDL_TextEditingEvent edit
Definition: SDL_events.h:501
DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len)
Definition: SDL_string.c:293
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:129
void SDL_ResetKeyboard(void)
Definition: SDL_keyboard.c:563
DECLSPEC void SDLCALL SDL_SetModState(SDL_Keymod modstate)
Set the current key modifier state for the keyboard.
Definition: SDL_keyboard.c:851
static SDL_Keyboard SDL_keyboard
Definition: SDL_keyboard.c:46
GLuint GLuint end
Definition: glew.h:1239
SDL_VideoDevice * SDL_GetVideoDevice(void)
Definition: SDL_video.c:548
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:137
General event structure.
Definition: SDL_events.h:495
DECLSPEC SDL_Window *SDLCALL SDL_GetKeyboardFocus(void)
Get the window which currently has keyboard focus.
Definition: SDL_keyboard.c:603
static char * SDL_UCS4ToUTF8(Uint32 ch, char *dst)
Definition: SDL_keyboard.c:511
#define SDL_PRESSED
Definition: SDL_events.h:50
void(* StartTextInput)(_THIS)
Definition: SDL_sysvideo.h:243
#define SDL_QUERY
Definition: SDL_events.h:685
int i
Definition: pngrutil.c:1377
#define SDL_RELEASED
Definition: SDL_events.h:49
DECLSPEC SDL_Keymod SDLCALL SDL_GetModState(void)
Get the current key modifier state for the keyboard.
Definition: SDL_keyboard.c:843
SDL_Scancode
The SDL keyboard scancode representation.
Definition: SDL_scancode.h:43
DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2)
Definition: SDL_string.c:946
int SDL_SendEditingText(const char *text, int start, int length)
Definition: SDL_keyboard.c:807
cl_event event
Definition: glew.h:3556