From 375858a20dcd36f9e2187af181228a9493d9f6e7 Mon Sep 17 00:00:00 2001 From: tma Date: Fri, 5 Sep 2008 23:38:35 +0000 Subject: * Add Com_HexStrToInt * Fixed some whacky indentation in q_shared.c * Allow single character keys e.g. 'c' to be used in cl_consoleKeys in addition to ASCII characters * Experimental code to ignore dead keys git-svn-id: svn://svn.icculus.org/quake3/trunk@1470 edf5b092-35ff-0310-97b2-ce42778d08ea --- code/sdl/sdl_input.c | 74 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 29 deletions(-) (limited to 'code/sdl') diff --git a/code/sdl/sdl_input.c b/code/sdl/sdl_input.c index b2fb981..a74887a 100644 --- a/code/sdl/sdl_input.c +++ b/code/sdl/sdl_input.c @@ -84,7 +84,7 @@ static void IN_PrintKey( const SDL_keysym *keysym, keyNum_t key, qboolean down ) else Com_Printf( " " ); - Com_Printf( "0x%hx \"%s\"", keysym->scancode, + Com_Printf( "0x%02x \"%s\"", keysym->scancode, SDL_GetKeyName( keysym->sym ) ); if( keysym->mod & KMOD_LSHIFT ) Com_Printf( " KMOD_LSHIFT" ); @@ -100,11 +100,11 @@ static void IN_PrintKey( const SDL_keysym *keysym, keyNum_t key, qboolean down ) if( keysym->mod & KMOD_MODE ) Com_Printf( " KMOD_MODE" ); if( keysym->mod & KMOD_RESERVED ) Com_Printf( " KMOD_RESERVED" ); - Com_Printf( " Q:%d(%s)", key, Key_KeynumToString( key ) ); + Com_Printf( " Q:0x%02x(%s)", key, Key_KeynumToString( key ) ); if( keysym->unicode ) { - Com_Printf( " U:%d", keysym->unicode ); + Com_Printf( " U:0x%02x", keysym->unicode ); if( keysym->unicode > ' ' && keysym->unicode < '~' ) Com_Printf( "(%c)", (char)keysym->unicode ); @@ -120,7 +120,7 @@ static void IN_PrintKey( const SDL_keysym *keysym, keyNum_t key, qboolean down ) IN_IsConsoleKey =============== */ -static qboolean IN_IsConsoleKey( keyNum_t key, const char character ) +static qboolean IN_IsConsoleKey( keyNum_t key, const unsigned char character ) { typedef struct consoleKey_s { @@ -133,7 +133,7 @@ static qboolean IN_IsConsoleKey( keyNum_t key, const char character ) union { keyNum_t key; - char character; + unsigned char character; } u; } consoleKey_t; @@ -153,34 +153,36 @@ static qboolean IN_IsConsoleKey( keyNum_t key, const char character ) while( numConsoleKeys < MAX_CONSOLE_KEYS ) { consoleKey_t *c = &consoleKeys[ numConsoleKeys ]; - char *keyName; + int charCode = 0; token = COM_Parse( &text_p ); if( !token[ 0 ] ) break; - c->u.key = Key_StringToKeynum( token ); + if( strlen( token ) == 4 ) + charCode = Com_HexStrToInt( token ); - // 0 isn't a key - if( c->u.key == 0 ) - continue; - - keyName = Key_KeynumToString( c->u.key ); - - if( strlen( keyName ) == 1 ) + if( charCode > 0 ) { c->type = CHARACTER; - c->u.character = *keyName; + c->u.character = (unsigned char)charCode; } else + { c->type = KEY; + c->u.key = Key_StringToKeynum( token ); + + // 0 isn't a key + if( c->u.key <= 0 ) + continue; + } numConsoleKeys++; } } - // Use the character in preference to the key name - if( character != '\0' ) + // If the character is the same as the key, prefer the character + if( key == character ) key = 0; for( i = 0; i < numConsoleKeys; i++ ) @@ -212,7 +214,7 @@ IN_TranslateSDLToQ3Key static const char *IN_TranslateSDLToQ3Key( SDL_keysym *keysym, keyNum_t *key, qboolean down ) { - static char buf[ 2 ] = { '\0', '\0' }; + static unsigned char buf[ 2 ] = { '\0', '\0' }; *buf = '\0'; *key = 0; @@ -311,9 +313,9 @@ static const char *IN_TranslateSDLToQ3Key( SDL_keysym *keysym, } } - if( down && keysym->unicode && !( keysym->unicode & 0xFF80 ) ) + if( down && keysym->unicode && !( keysym->unicode & 0xFF00 ) ) { - char ch = (char)keysym->unicode & 0x7F; + unsigned char ch = (unsigned char)keysym->unicode & 0xFF; switch( ch ) { @@ -333,6 +335,17 @@ static const char *IN_TranslateSDLToQ3Key( SDL_keysym *keysym, if( in_keyboardDebug->integer ) IN_PrintKey( keysym, *key, down ); + // Keys that have ASCII names but produce no character are probably + // dead keys -- ignore them + if( down && strlen( Key_KeynumToString( *key ) ) == 1 && + keysym->unicode == 0 ) + { + if( in_keyboardDebug->integer ) + Com_Printf( " Ignored dead key '%c'\n", *key ); + + *key = 0; + } + if( IN_IsConsoleKey( *key, *buf ) ) { // Console keys can't be bound or generate characters @@ -340,7 +353,11 @@ static const char *IN_TranslateSDLToQ3Key( SDL_keysym *keysym, *buf = '\0'; } - return buf; + // Don't allow extended ASCII to generate characters + if( *buf & 0x80 ) + *buf = '\0'; + + return (char *)buf; } #ifdef MACOS_X_ACCELERATION_HACK @@ -817,7 +834,7 @@ IN_ProcessEvents static void IN_ProcessEvents( void ) { SDL_Event e; - const char *p = NULL; + const char *character = NULL; keyNum_t key = 0; if( !SDL_WasInit( SDL_INIT_VIDEO ) ) @@ -840,20 +857,19 @@ static void IN_ProcessEvents( void ) switch( e.type ) { case SDL_KEYDOWN: - p = IN_TranslateSDLToQ3Key( &e.key.keysym, &key, qtrue ); + character = IN_TranslateSDLToQ3Key( &e.key.keysym, &key, qtrue ); if( key ) Com_QueueEvent( 0, SE_KEY, key, qtrue, 0, NULL ); - if( p ) - { - while( *p ) - Com_QueueEvent( 0, SE_CHAR, *p++, 0, 0, NULL ); - } + if( character ) + Com_QueueEvent( 0, SE_CHAR, *character, 0, 0, NULL ); break; case SDL_KEYUP: IN_TranslateSDLToQ3Key( &e.key.keysym, &key, qfalse ); - Com_QueueEvent( 0, SE_KEY, key, qfalse, 0, NULL ); + + if( key ) + Com_QueueEvent( 0, SE_KEY, key, qfalse, 0, NULL ); break; case SDL_MOUSEMOTION: -- cgit v1.2.3