void SetDefaultBinds_onUnusedKeys() { bind_t* bindptr; int i; char buff[8]; if(!wop_AutoBindUnusedKeys.integer) return; bindptr = g_bindings; for (i=0; ;i++,bindptr++) { if (!bindptr->label) break; if(bindptr->defaultbind1==-1) continue; buff[0]=0; trap_Key_GetBindingBuf(bindptr->defaultbind1,buff,8); if(buff[0]==0) trap_Key_SetBinding(bindptr->defaultbind1,bindptr->command); if(bindptr->defaultbind2==-1) continue; buff[0]=0; trap_Key_GetBindingBuf(bindptr->defaultbind2,buff,8); if(buff[0]==0) trap_Key_SetBinding(bindptr->defaultbind2,bindptr->command); } }
/* ================ CG_KeyBinding ================ */ char *CG_KeyBinding( const char *bind ) { static char key[ 32 ]; char bindbuff[ MAX_CVAR_VALUE_STRING ]; int i; key[ 0 ] = '\0'; // NOTE: change K_LAST_KEY to MAX_KEYS for full key support (eventually) for ( i = 0; i < K_LAST_KEY; i++ ) { trap_Key_GetBindingBuf( i, bindbuff, sizeof( bindbuff ) ); if ( !Q_stricmp( bindbuff, bind ) ) { trap_Key_KeynumToStringBuf( i, key, sizeof( key ) ); break; } } if ( !key[ 0 ] ) { Q_strncpyz( key, "\\", sizeof( key ) ); Q_strcat( key, sizeof( key ), bind ); } return key; }
/* ================= CG_GetBindings ================= */ static void CG_GetBindings( void ) { int i, j, numKeys; char buffer[ MAX_STRING_CHARS ]; for( i = 0; i < numBindings; i++ ) { bindings[ i ].keys[ 0 ] = bindings[ i ].keys[ 1 ] = K_NONE; numKeys = 0; for( j = 0; j < K_LAST_KEY; j++ ) { trap_Key_GetBindingBuf( j, buffer, MAX_STRING_CHARS ); if( buffer[ 0 ] == 0 ) continue; if( !Q_stricmp( buffer, bindings[ i ].command ) ) { bindings[ i ].keys[ numKeys++ ] = j; if( numKeys > 1 ) break; } } } }
/* ================= Controls_GetKeyAssignment ================= */ static void Controls_GetKeyAssignment (char *command, int *twokeys) { int count; int j; char b[256]; twokeys[0] = twokeys[1] = -1; count = 0; for (j = 0; j < 256; j++) { trap_Key_GetBindingBuf(j, b, 256); if (*b == 0) { continue; } if (!Q_stricmp(b, command)) { twokeys[count] = j; count++; if (count == 2) break; } } }
/* ================= CG_GetBindings ================= */ static void CG_GetBindings( team_t team ) { unsigned i, j, numKeys; char buffer[ MAX_STRING_CHARS ]; for ( i = 0; i < numBindings; i++ ) { bindings[ i ].keys[ 0 ] = bindings[ i ].keys[ 1 ] = K_NONE; numKeys = 0; for ( j = 0; j < MAX_KEYS; j++ ) { trap_Key_GetBindingBuf( j, team, buffer, MAX_STRING_CHARS ); if ( team != TEAM_NONE && buffer[ 0 ] == 0 ) { trap_Key_GetBindingBuf( j, TEAM_NONE, buffer, MAX_STRING_CHARS ); } if ( buffer[ 0 ] == 0 ) { continue; } if ( !Q_stricmp( buffer, bindings[ i ].command ) ) { bindings[ i ].keys[ numKeys++ ] = j; if ( numKeys > 1 ) { break; } } } } }
char *CG_getBindKeyName(const char *cmd, char *buf, int len) { int j; for(j=0; j<256; j++) { trap_Key_GetBindingBuf(j, buf, len); if(*buf == 0) continue; if(!Q_stricmp(buf, cmd)) { trap_Key_KeynumToStringBuf(j, buf, MAX_STRING_TOKENS); Q_strupr(buf); return(buf); } } Q_strncpyz(buf, va("(%s)", cmd), len); return(buf); }
void CG_GetBoundKeysString( const char *cmd, char *keys, size_t keysSize ) { int key; const char *bind; int numKeys = 0; const char *keyNames[2]; char charKeys[2][2]; memset( charKeys, 0, sizeof( charKeys ) ); for( key = 0; key < 256; key++ ) { bind = trap_Key_GetBindingBuf( key ); if( !bind || Q_stricmp( bind, cmd ) ) continue; if( ( key >= 'a' ) && ( key <= 'z' ) ) { charKeys[numKeys][0] = key - ( 'a' - 'A' ); keyNames[numKeys] = charKeys[numKeys]; } else { keyNames[numKeys] = trap_Key_KeynumToString( key ); } numKeys++; if( numKeys == 2 ) break; } if( !numKeys ) keyNames[0] = CG_TranslateString( "UNBOUND" ); if( numKeys == 2 ) Q_snprintfz( keys, keysSize, CG_TranslateString( "%s or %s" ), keyNames[0], keyNames[1] ); else Q_strncpyz( keys, keyNames[0], keysSize ); }