try to fix keyboard handling. Works with German keyboard now AFAICT

This commit is contained in:
Ludwig Nussel 2005-08-31 19:54:08 +00:00
parent 2282c30923
commit 5af249432d
1 changed files with 38 additions and 31 deletions

View File

@ -76,6 +76,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define WINDOW_CLASS_NAME "Quake III: Arena" #define WINDOW_CLASS_NAME "Quake III: Arena"
#define WINDOW_CLASS_NAME_BRIEF "quake3" #define WINDOW_CLASS_NAME_BRIEF "quake3"
//#define KBD_DBG
typedef enum typedef enum
{ {
RSERR_OK, RSERR_OK,
@ -149,24 +151,19 @@ static const char *Q_stristr( const char *s, const char *find)
return s; return s;
} }
//#define KBD_DBG
static const char *XLateKey(SDL_keysym *keysym, int *key) static const char *XLateKey(SDL_keysym *keysym, int *key)
{ {
static char buf[2] = { '\0', '\0' }; static char buf[2] = { '\0', '\0' };
*key = 0; *key = 0;
*buf = '\0';
// these happen to match the ASCII chars. // these happen to match the ASCII chars.
if ( ((keysym->sym >= SDLK_a) && (keysym->sym <= SDLK_z)) || if ((keysym->sym >= ' ') && (keysym->sym <= '~'))
((keysym->sym >= SDLK_0) && (keysym->sym <= SDLK_9)) )
{ {
*key = (int) keysym->sym; *key = (int) keysym->sym;
buf[0] = (char) *key;
return buf;
} }
else
buf[0] = '\0';
switch (keysym->sym) switch (keysym->sym)
{ {
case SDLK_PAGEUP: *key = K_PGUP; break; case SDLK_PAGEUP: *key = K_PGUP; break;
@ -203,8 +200,7 @@ static const char *XLateKey(SDL_keysym *keysym, int *key)
case SDLK_F12: *key = K_F12; break; case SDLK_F12: *key = K_F12; break;
// bk001206 - from Ryan's Fakk2 // bk001206 - from Ryan's Fakk2
//case SDLK_BackSpace: *key = 8; break; // ctrl-h case SDLK_BACKSPACE: *key = K_BACKSPACE; break; // ctrl-h
case SDLK_BACKSPACE: *key = K_BACKSPACE; buf[0] = 8; break; // ctrl-h
case SDLK_KP_PERIOD: *key = K_KP_DEL; break; case SDLK_KP_PERIOD: *key = K_KP_DEL; break;
case SDLK_DELETE: *key = K_DEL; break; case SDLK_DELETE: *key = K_DEL; break;
case SDLK_PAUSE: *key = K_PAUSE; break; case SDLK_PAUSE: *key = K_PAUSE; break;
@ -227,28 +223,22 @@ static const char *XLateKey(SDL_keysym *keysym, int *key)
case SDLK_KP_PLUS: *key = K_KP_PLUS; break; case SDLK_KP_PLUS: *key = K_KP_PLUS; break;
case SDLK_KP_MINUS: *key = K_KP_MINUS; break; case SDLK_KP_MINUS: *key = K_KP_MINUS; break;
case SDLK_KP_DIVIDE: *key = K_KP_SLASH; break; case SDLK_KP_DIVIDE: *key = K_KP_SLASH; break;
case SDLK_SPACE: *key = K_SPACE; break; default: break;
// !!! FIXME: Console key...may not be accurate on all keyboards!
case SDLK_BACKQUOTE: *key = '~'; break;
default:
if (keysym->unicode <= 255) // maps to ASCII?
{
char ch = (char) keysym->unicode;
if (ch >= 'A' && ch <= 'Z')
ch = ch - 'A' + 'a';
// if ctrl is pressed, the keys are not between 'A' and 'Z', for instance ctrl-z == 26 ^Z ^C etc.
// see https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=19
else if (ch >= 1 && ch <= 26)
ch = ch + 'a' - 1;
buf[0] = ch;
return buf;
}
break;
} }
if (keysym->unicode <= 255 && keysym->unicode >= 20) // maps to ASCII?
{
char ch = (char) keysym->unicode;
if (ch == '~')
*key = '~'; // console HACK
else if (ch >= 'A' && ch <= 'Z')
ch = ch - 'A' + 'a';
buf[0] = ch;
}
else if(keysym->unicode == 8) // ctrl-h
buf[0] = 8;
return buf; return buf;
} }
@ -264,6 +254,21 @@ static void uninstall_grabs(void)
SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_WM_GrabInput(SDL_GRAB_OFF);
} }
static void printkey(const SDL_Event* event)
{
#ifdef KBD_DBG
printf("key name: %s", SDL_GetKeyName(event->key.keysym.sym));
if(event->key.keysym.unicode)
{
printf(" unicode: %hx", event->key.keysym.unicode);
if (event->key.keysym.unicode >= '0'
&& event->key.keysym.unicode <= '~') // printable?
printf(" (%c)", (unsigned char)(event->key.keysym.unicode));
}
puts("");
#endif
}
static void HandleEvents(void) static void HandleEvents(void)
{ {
const int t = 0; // always just use the current time. const int t = 0; // always just use the current time.
@ -297,6 +302,7 @@ static void HandleEvents(void)
switch (e.type) switch (e.type)
{ {
case SDL_KEYDOWN: case SDL_KEYDOWN:
printkey(&e);
p = XLateKey(&e.key.keysym, &key); p = XLateKey(&e.key.keysym, &key);
if (key) if (key)
{ {
@ -1420,3 +1426,4 @@ void IN_JoyMove( void )
// end of linux_glimp_sdl.c ... // end of linux_glimp_sdl.c ...