src/events/SDL_keyboard.c
branchSDL-1.2
changeset 4138 b1fd24d62e55
parent 1760 a9be6a3a51d1
child 4159 a1b03ba2fcd0
     1.1 --- a/src/events/SDL_keyboard.c	Mon Feb 04 17:22:56 2008 +0000
     1.2 +++ b/src/events/SDL_keyboard.c	Tue Feb 26 10:50:28 2008 +0000
     1.3 @@ -48,9 +48,16 @@
     1.4  	SDL_Event evt;    /* the event we are supposed to repeat */
     1.5  } SDL_KeyRepeat;
     1.6  
     1.7 +/* Global no-lock-keys support */
     1.8 +static Uint8 SDL_NoLockKeys;
     1.9 +
    1.10 +#define SDL_NLK_CAPS 0x01
    1.11 +#define SDL_NLK_NUM  0x02
    1.12 +
    1.13  /* Public functions */
    1.14  int SDL_KeyboardInit(void)
    1.15  {
    1.16 +	const char* env;
    1.17  	SDL_VideoDevice *video = current_video;
    1.18  	SDL_VideoDevice *this  = current_video;
    1.19  
    1.20 @@ -65,6 +72,25 @@
    1.21  
    1.22  	SDL_EnableKeyRepeat(0, 0);
    1.23  
    1.24 +	/* Allow environment override to disable special lock-key behavior */
    1.25 +	env = getenv("SDL_NO_LOCK_KEYS");
    1.26 +	SDL_NoLockKeys = 0;
    1.27 +	if (env) {
    1.28 +		switch (SDL_atoi(env)) {
    1.29 +			case 1:
    1.30 +				SDL_NoLockKeys = SDL_NLK_CAPS | SDL_NLK_NUM;
    1.31 +				break;
    1.32 +			case 2:
    1.33 +				SDL_NoLockKeys = SDL_NLK_CAPS;
    1.34 +				break;
    1.35 +			case 3:
    1.36 +				SDL_NoLockKeys = SDL_NLK_NUM;
    1.37 +				break;
    1.38 +			default:
    1.39 +				break;
    1.40 +		}
    1.41 +	}
    1.42 +
    1.43  	/* Fill in the blanks in keynames */
    1.44  	keynames[SDLK_BACKSPACE] = "backspace";
    1.45  	keynames[SDLK_TAB] = "tab";
    1.46 @@ -394,12 +420,16 @@
    1.47  				break;
    1.48  			case SDLK_NUMLOCK:
    1.49  				modstate ^= KMOD_NUM;
    1.50 +				if ( SDL_NoLockKeys & SDL_NLK_NUM )
    1.51 +					break;
    1.52  				if ( ! (modstate&KMOD_NUM) )
    1.53  					state = SDL_RELEASED;
    1.54  				keysym->mod = (SDLMod)modstate;
    1.55  				break;
    1.56  			case SDLK_CAPSLOCK:
    1.57  				modstate ^= KMOD_CAPS;
    1.58 +				if ( SDL_NoLockKeys & SDL_NLK_CAPS )
    1.59 +					break;
    1.60  				if ( ! (modstate&KMOD_CAPS) )
    1.61  					state = SDL_RELEASED;
    1.62  				keysym->mod = (SDLMod)modstate;
    1.63 @@ -440,7 +470,13 @@
    1.64  			case SDLK_UNKNOWN:
    1.65  				break;
    1.66  			case SDLK_NUMLOCK:
    1.67 +				if ( SDL_NoLockKeys & SDL_NLK_NUM )
    1.68 +					break;
    1.69 +				/* Only send keydown events */
    1.70 +				return(0);
    1.71  			case SDLK_CAPSLOCK:
    1.72 +				if ( SDL_NoLockKeys & SDL_NLK_CAPS )
    1.73 +					break;
    1.74  				/* Only send keydown events */
    1.75  				return(0);
    1.76  			case SDLK_LCTRL: