comparison src/events/SDL_keyboard.c @ 4138:b1fd24d62e55 SDL-1.2

Date: Tue, 05 Feb 2008 01:41:08 -0500 From: Mike Miscevic Subject: SDL and capslock/numlock Find attached a patch against SDL-1.2.13 for check of SDL_NO_LOCK_KEYS environment variable. This differs slightly from other patches I've seen in that it has 3 modes: Disable CAPS-LOCK and NUM-LOCK supression of down+up key events, suitable for games where the player needs these keys to do more than just toggle. A value of 1 will effect both CAPS-LOCK and NUM-LOCK. A value of 2 will effect only CAPS-LOCK. A value of 3 will effect only NUM-LOCK. All other values have no effect. This works for me and has been tested on: - Fedora 8 64-bit - SRCRPM SDL-1.2.13-1.fc8.src.rpm - Emeny Territory Quake Wars (ETQW), native 32-bit commercial game --Mike Miscevic
author Sam Lantinga <slouken@libsdl.org>
date Tue, 26 Feb 2008 10:50:28 +0000
parents a9be6a3a51d1
children a1b03ba2fcd0
comparison
equal deleted inserted replaced
4137:be12463f31ea 4138:b1fd24d62e55
46 Uint32 timestamp; /* the time the first keydown event occurred */ 46 Uint32 timestamp; /* the time the first keydown event occurred */
47 47
48 SDL_Event evt; /* the event we are supposed to repeat */ 48 SDL_Event evt; /* the event we are supposed to repeat */
49 } SDL_KeyRepeat; 49 } SDL_KeyRepeat;
50 50
51 /* Global no-lock-keys support */
52 static Uint8 SDL_NoLockKeys;
53
54 #define SDL_NLK_CAPS 0x01
55 #define SDL_NLK_NUM 0x02
56
51 /* Public functions */ 57 /* Public functions */
52 int SDL_KeyboardInit(void) 58 int SDL_KeyboardInit(void)
53 { 59 {
60 const char* env;
54 SDL_VideoDevice *video = current_video; 61 SDL_VideoDevice *video = current_video;
55 SDL_VideoDevice *this = current_video; 62 SDL_VideoDevice *this = current_video;
56 63
57 /* Set default mode of UNICODE translation */ 64 /* Set default mode of UNICODE translation */
58 SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION); 65 SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION);
62 SDL_memset((void*)keynames, 0, sizeof(keynames)); 69 SDL_memset((void*)keynames, 0, sizeof(keynames));
63 SDL_memset(SDL_KeyState, 0, sizeof(SDL_KeyState)); 70 SDL_memset(SDL_KeyState, 0, sizeof(SDL_KeyState));
64 video->InitOSKeymap(this); 71 video->InitOSKeymap(this);
65 72
66 SDL_EnableKeyRepeat(0, 0); 73 SDL_EnableKeyRepeat(0, 0);
74
75 /* Allow environment override to disable special lock-key behavior */
76 env = getenv("SDL_NO_LOCK_KEYS");
77 SDL_NoLockKeys = 0;
78 if (env) {
79 switch (SDL_atoi(env)) {
80 case 1:
81 SDL_NoLockKeys = SDL_NLK_CAPS | SDL_NLK_NUM;
82 break;
83 case 2:
84 SDL_NoLockKeys = SDL_NLK_CAPS;
85 break;
86 case 3:
87 SDL_NoLockKeys = SDL_NLK_NUM;
88 break;
89 default:
90 break;
91 }
92 }
67 93
68 /* Fill in the blanks in keynames */ 94 /* Fill in the blanks in keynames */
69 keynames[SDLK_BACKSPACE] = "backspace"; 95 keynames[SDLK_BACKSPACE] = "backspace";
70 keynames[SDLK_TAB] = "tab"; 96 keynames[SDLK_TAB] = "tab";
71 keynames[SDLK_CLEAR] = "clear"; 97 keynames[SDLK_CLEAR] = "clear";
392 switch (keysym->sym) { 418 switch (keysym->sym) {
393 case SDLK_UNKNOWN: 419 case SDLK_UNKNOWN:
394 break; 420 break;
395 case SDLK_NUMLOCK: 421 case SDLK_NUMLOCK:
396 modstate ^= KMOD_NUM; 422 modstate ^= KMOD_NUM;
423 if ( SDL_NoLockKeys & SDL_NLK_NUM )
424 break;
397 if ( ! (modstate&KMOD_NUM) ) 425 if ( ! (modstate&KMOD_NUM) )
398 state = SDL_RELEASED; 426 state = SDL_RELEASED;
399 keysym->mod = (SDLMod)modstate; 427 keysym->mod = (SDLMod)modstate;
400 break; 428 break;
401 case SDLK_CAPSLOCK: 429 case SDLK_CAPSLOCK:
402 modstate ^= KMOD_CAPS; 430 modstate ^= KMOD_CAPS;
431 if ( SDL_NoLockKeys & SDL_NLK_CAPS )
432 break;
403 if ( ! (modstate&KMOD_CAPS) ) 433 if ( ! (modstate&KMOD_CAPS) )
404 state = SDL_RELEASED; 434 state = SDL_RELEASED;
405 keysym->mod = (SDLMod)modstate; 435 keysym->mod = (SDLMod)modstate;
406 break; 436 break;
407 case SDLK_LCTRL: 437 case SDLK_LCTRL:
438 } else { 468 } else {
439 switch (keysym->sym) { 469 switch (keysym->sym) {
440 case SDLK_UNKNOWN: 470 case SDLK_UNKNOWN:
441 break; 471 break;
442 case SDLK_NUMLOCK: 472 case SDLK_NUMLOCK:
473 if ( SDL_NoLockKeys & SDL_NLK_NUM )
474 break;
475 /* Only send keydown events */
476 return(0);
443 case SDLK_CAPSLOCK: 477 case SDLK_CAPSLOCK:
478 if ( SDL_NoLockKeys & SDL_NLK_CAPS )
479 break;
444 /* Only send keydown events */ 480 /* Only send keydown events */
445 return(0); 481 return(0);
446 case SDLK_LCTRL: 482 case SDLK_LCTRL:
447 modstate &= ~KMOD_LCTRL; 483 modstate &= ~KMOD_LCTRL;
448 break; 484 break;