diff options
Diffstat (limited to 'src/client/cl_keys.c')
-rw-r--r-- | src/client/cl_keys.c | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/src/client/cl_keys.c b/src/client/cl_keys.c index 8bd0b654..95858d40 100644 --- a/src/client/cl_keys.c +++ b/src/client/cl_keys.c @@ -1074,6 +1074,23 @@ void CL_InitKeyCommands( void ) { /* =================== +CL_BindUICommand + +Returns qtrue if bind command should be executed while user interface is shown +=================== +*/ +static qboolean CL_BindUICommand( const char *cmd ) { + if ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) + return qfalse; + + if ( !Q_stricmp( cmd, "togglemenu" ) ) + return qtrue; + + return qfalse; +} + +/* +=================== CL_ParseBinding Execute the commands in the bind string @@ -1082,11 +1099,20 @@ Execute the commands in the bind string void CL_ParseBinding( int key, qboolean down, unsigned time ) { char buf[ MAX_STRING_CHARS ], *p = buf, *end; + qboolean allCommands, allowUpCmds; + if( clc.state == CA_DISCONNECTED && Key_GetCatcher( ) == 0 ) + return; if( !keys[key].binding || !keys[key].binding[0] ) return; Q_strncpyz( buf, keys[key].binding, sizeof( buf ) ); + // run all bind commands if console, ui, etc aren't reading keys + allCommands = ( Key_GetCatcher( ) == 0 ); + + // allow button up commands if in game even if key catcher is set + allowUpCmds = ( clc.state != CA_DISCONNECTED ); + while( 1 ) { while( isspace( *p ) ) @@ -1099,16 +1125,20 @@ void CL_ParseBinding( int key, qboolean down, unsigned time ) // button commands add keynum and time as parameters // so that multiple sources can be discriminated and // subframe corrected - char cmd[1024]; - Com_sprintf( cmd, sizeof( cmd ), "%c%s %d %d\n", - ( down ) ? '+' : '-', p + 1, key, time ); - Cbuf_AddText( cmd ); + if ( allCommands || ( allowUpCmds && !down ) ) { + char cmd[1024]; + Com_sprintf( cmd, sizeof( cmd ), "%c%s %d %d\n", + ( down ) ? '+' : '-', p + 1, key, time ); + Cbuf_AddText( cmd ); + } } else if( down ) { // normal commands only execute on key press - Cbuf_AddText( p ); - Cbuf_AddText( "\n" ); + if ( allCommands || CL_BindUICommand( p ) ) { + Cbuf_AddText( p ); + Cbuf_AddText( "\n" ); + } } if( !end ) break; @@ -1194,10 +1224,10 @@ void CL_KeyDownEvent( int key, unsigned time ) } } else if ( clc.state == CA_DISCONNECTED ) { Console_Key( key ); - } else { - // send the bound action - CL_ParseBinding( key, qtrue, time ); } + + // send the bound action + CL_ParseBinding( key, qtrue, time ); return; } @@ -1229,8 +1259,7 @@ void CL_KeyUpEvent( int key, unsigned time ) // console mode and menu mode, to keep the character from continuing // an action started before a mode switch. // - if( clc.state != CA_DISCONNECTED ) - CL_ParseBinding( key, qfalse, time ); + CL_ParseBinding( key, qfalse, time ); if ( Key_GetCatcher( ) & KEYCATCH_UI && uivm ) { VM_Call( uivm, UI_KEY_EVENT, key, qfalse ); |