Improve console key situation

This commit is contained in:
Tim Angus 2013-01-21 22:20:15 +00:00
parent 9b8711d2e1
commit 42586b782b

View file

@ -67,8 +67,9 @@ static void IN_PrintKey( const SDL_Keysym *keysym, keyNum_t key, qboolean down )
else else
Com_Printf( " " ); Com_Printf( " " );
Com_Printf( "0x%02x \"%s\"", keysym->scancode, Com_Printf( "Scancode: 0x%02x(%s) Sym: 0x%02x(%s)",
SDL_GetKeyName( keysym->sym ) ); keysym->scancode, SDL_GetScancodeName( keysym->scancode ),
keysym->sym, SDL_GetKeyName( keysym->sym ) );
if( keysym->mod & KMOD_LSHIFT ) Com_Printf( " KMOD_LSHIFT" ); if( keysym->mod & KMOD_LSHIFT ) Com_Printf( " KMOD_LSHIFT" );
if( keysym->mod & KMOD_RSHIFT ) Com_Printf( " KMOD_RSHIFT" ); if( keysym->mod & KMOD_RSHIFT ) Com_Printf( " KMOD_RSHIFT" );
@ -91,23 +92,25 @@ static void IN_PrintKey( const SDL_Keysym *keysym, keyNum_t key, qboolean down )
/* /*
=============== ===============
IN_IsConsoleKey IN_IsConsoleKey
//FIXME: SDL 1.3 allow scancode based console key selection
TODO: If the SDL_Scancode situation improves, use it instead of
both of these methods
=============== ===============
*/ */
static qboolean IN_IsConsoleKey( keyNum_t key, const unsigned char character ) static qboolean IN_IsConsoleKey( keyNum_t key, int character )
{ {
typedef struct consoleKey_s typedef struct consoleKey_s
{ {
enum enum
{ {
KEY, QUAKE_KEY,
CHARACTER CHARACTER
} type; } type;
union union
{ {
keyNum_t key; keyNum_t key;
unsigned char character; int character;
} u; } u;
} consoleKey_t; } consoleKey_t;
@ -139,11 +142,11 @@ static qboolean IN_IsConsoleKey( keyNum_t key, const unsigned char character )
if( charCode > 0 ) if( charCode > 0 )
{ {
c->type = CHARACTER; c->type = CHARACTER;
c->u.character = (unsigned char)charCode; c->u.character = charCode;
} }
else else
{ {
c->type = KEY; c->type = QUAKE_KEY;
c->u.key = Key_StringToKeynum( token ); c->u.key = Key_StringToKeynum( token );
// 0 isn't a key // 0 isn't a key
@ -165,7 +168,7 @@ static qboolean IN_IsConsoleKey( keyNum_t key, const unsigned char character )
switch( c->type ) switch( c->type )
{ {
case KEY: case QUAKE_KEY:
if( key && c->u.key == key ) if( key && c->u.key == key )
return qtrue; return qtrue;
break; break;
@ -277,7 +280,7 @@ static keyNum_t IN_TranslateSDLToQ3Key( SDL_Keysym *keysym, qboolean down )
if( in_keyboardDebug->integer ) if( in_keyboardDebug->integer )
IN_PrintKey( keysym, key, down ); IN_PrintKey( keysym, key, down );
if( IN_IsConsoleKey( key, '\0' ) ) if( IN_IsConsoleKey( key, 0 ) )
{ {
// Console keys can't be bound or generate characters // Console keys can't be bound or generate characters
key = K_CONSOLE; key = K_CONSOLE;
@ -706,6 +709,7 @@ static void IN_ProcessEvents( void )
{ {
SDL_Event e; SDL_Event e;
keyNum_t key = 0; keyNum_t key = 0;
static keyNum_t lastKeyDown = 0;
if( !SDL_WasInit( SDL_INIT_VIDEO ) ) if( !SDL_WasInit( SDL_INIT_VIDEO ) )
return; return;
@ -715,19 +719,21 @@ static void IN_ProcessEvents( void )
switch( e.type ) switch( e.type )
{ {
case SDL_KEYDOWN: case SDL_KEYDOWN:
key = IN_TranslateSDLToQ3Key( &e.key.keysym, qtrue ); if( ( key = IN_TranslateSDLToQ3Key( &e.key.keysym, qtrue ) ) )
if( key )
Com_QueueEvent( 0, SE_KEY, key, qtrue, 0, NULL ); Com_QueueEvent( 0, SE_KEY, key, qtrue, 0, NULL );
lastKeyDown = key;
break; break;
case SDL_KEYUP: case SDL_KEYUP:
key = IN_TranslateSDLToQ3Key( &e.key.keysym, qfalse ); if( ( key = IN_TranslateSDLToQ3Key( &e.key.keysym, qfalse ) ) )
if( key )
Com_QueueEvent( 0, SE_KEY, key, qfalse, 0, NULL ); Com_QueueEvent( 0, SE_KEY, key, qfalse, 0, NULL );
lastKeyDown = 0;
break; break;
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
if( lastKeyDown != K_CONSOLE )
{ {
char *c = e.text.text; char *c = e.text.text;
@ -763,7 +769,15 @@ static void IN_ProcessEvents( void )
} }
if( utf32 != 0 ) if( utf32 != 0 )
Com_QueueEvent( 0, SE_CHAR, utf32, 0, 0, NULL ); {
if( IN_IsConsoleKey( 0, utf32 ) )
{
Com_QueueEvent( 0, SE_KEY, K_CONSOLE, qtrue, 0, NULL );
Com_QueueEvent( 0, SE_KEY, K_CONSOLE, qfalse, 0, NULL );
}
else
Com_QueueEvent( 0, SE_CHAR, utf32, 0, 0, NULL );
}
} }
} }
break; break;