Package: libsdl1.2
Severity: normal
Tags: patch
SDL gives the caps-lock and num-lock keys a special treatment for
handling events: On key press, the state is changed and a pressed or
released event is generated accordingly, actual key release is
completely ignored. For applications which require text input, this is
fine, but if the lock keys are to be used as "just any key", for example
for controlling the movement of a player in a game, this is a problem.
The attached patch keeps the old behaviour by default, but does not give
the keys any special treatment (well, in fact, they don't repeat) if the
environment variable "SDL_DISABLE_LOCK_KEYS" is set at application
startup. The application can force this by setting it before calling
SDL functions.
Thanks,
Bas Wijnen
-- System Information:
Debian Release: testing/unstable
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.11
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
diff -urp SDL-1.2.7+1.2.8cvs20041007/src/events/SDL_keyboard.c SDL-1.2.7+1.2.8cvs20041007.new/src/events/SDL_keyboard.c
--- SDL-1.2.7+1.2.8cvs20041007/src/events/SDL_keyboard.c 2004-01-04 17:49:17.000000000 +0100
+++ SDL-1.2.7+1.2.8cvs20041007.new/src/events/SDL_keyboard.c 2005-07-05 16:14:38.000000000 +0200
@@ -42,6 +42,7 @@ static char rcsid =
/* Global keystate information */
static Uint8 SDL_KeyState[SDLK_LAST];
static SDLMod SDL_ModState;
+static int SDL_UseLockKeys;
int SDL_TranslateUNICODE = 0;
static char *keynames[SDLK_LAST]; /* Array of keycode names */
@@ -77,6 +78,7 @@ int SDL_KeyboardInit(void)
video->InitOSKeymap(this);
SDL_EnableKeyRepeat(0, 0);
+ SDL_UseLockKeys = getenv ("SDL_DISABLE_LOCK_KEYS") == NULL;
/* Fill in the blanks in keynames */
keynames[SDLK_BACKSPACE] = "backspace";
@@ -384,6 +386,7 @@ int SDL_PrivateKeyboard(Uint8 state, SDL
SDL_Event event;
int posted, repeatable;
Uint16 modstate;
+ int use_lock_keys;
memset(&event, 0, sizeof(event));
@@ -395,17 +398,22 @@ printf("The '%s' key has been %s\n", SDL
modstate = (Uint16)SDL_ModState;
repeatable = 0;
+ use_lock_keys = SDL_UseLockKeys;
if ( state == SDL_PRESSED ) {
keysym->mod = (SDLMod)modstate;
switch (keysym->sym) {
case SDLK_NUMLOCK:
+ if (!use_lock_keys)
+ break;
modstate ^= KMOD_NUM;
if ( ! (modstate&KMOD_NUM) )
state = SDL_RELEASED;
keysym->mod = (SDLMod)modstate;
break;
case SDLK_CAPSLOCK:
+ if (!use_lock_keys)
+ break;
modstate ^= KMOD_CAPS;
if ( ! (modstate&KMOD_CAPS) )
state = SDL_RELEASED;
@@ -446,6 +454,8 @@ printf("The '%s' key has been %s\n", SDL
switch (keysym->sym) {
case SDLK_NUMLOCK:
case SDLK_CAPSLOCK:
+ if (!use_lock_keys)
+ break;
/* Only send keydown events */
return(0);
case SDLK_LCTRL: