=================== 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. =================== */
| 809 | =================== |
| 810 | */ |
| 811 | int 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 | |
| 836 | static char tinyString[16]; |
| 837 | static const char *Key_KeynumValid( int keynum ) { |
no test coverage detected