summaryrefslogtreecommitdiff
path: root/src/sdl/sdl_input.c
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2009-10-03 12:31:59 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:16:03 +0000
commit304d4258d3a49488f570b8ad71931faa7e5d40ba (patch)
treebf9ec15bd9154305ff9fab2943b3daf25024f8a5 /src/sdl/sdl_input.c
parent6e90e4e7861f5cb354487d1fe0f1fd06c385308e (diff)
* Merge ioq3-r1498, by popular demand
Diffstat (limited to 'src/sdl/sdl_input.c')
-rw-r--r--src/sdl/sdl_input.c74
1 files changed, 45 insertions, 29 deletions
diff --git a/src/sdl/sdl_input.c b/src/sdl/sdl_input.c
index 98f8525a..3263932a 100644
--- a/src/sdl/sdl_input.c
+++ b/src/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
@@ -865,7 +882,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 ) )
@@ -888,20 +905,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: