MCPcopy Create free account
hub / github.com/JACoders/OpenJK / Key_StringToKeynum

Function Key_StringToKeynum

code/client/cl_keys.cpp:811–834  ·  view source on GitHub ↗

=================== Key_StringToKeynum Returns a key number to be used to index keys[] by looking at the given string. Single ascii characters return themselves, while the K_* names are matched up. 0x11 will be interpreted as raw hex, which will allow new controlers to be configured even if they don't have defined names. =================== */

Source from the content-addressed store, hash-verified

809===================
810*/
811int Key_StringToKeynum( char *str ) {
812 if ( !VALIDSTRING( str ) )
813 return -1;
814
815 // If single char bind, presume ascii char bind
816 if ( !str[1] )
817 return keynames[(unsigned char)str[0]].upper;
818
819 // scan for a text match
820 for ( int i=0; i<MAX_KEYS; i++ ) {
821 if ( keynames[i].name && !Q_stricmp( str, keynames[i].name ) )
822 return keynames[i].keynum;
823 }
824
825 // check for hex code
826 if ( strlen( str ) == 4 ) {
827 int n = Com_HexStrToInt( str );
828
829 if ( n >= 0 )
830 return n;
831 }
832
833 return -1;
834}
835
836static char tinyString[16];
837static const char *Key_KeynumValid( int keynum ) {

Callers 3

Key_Unbind_fFunction · 0.70
Key_Bind_fFunction · 0.70
IN_IsConsoleKeyFunction · 0.50

Calls 3

VALIDSTRINGFunction · 0.85
Q_stricmpFunction · 0.85
Com_HexStrToIntFunction · 0.50

Tested by

no test coverage detected