diff --git a/include/keys.h b/include/keys.h index 4c77bd9..f983a14 100644 --- a/include/keys.h +++ b/include/keys.h @@ -31,6 +31,7 @@ #define _KEYS_H #include "quakeio.h" +#include "wtoi.h" // these are the key numbers that should be passed to Key_Event @@ -168,6 +169,12 @@ typedef enum { K_MWHEELDOWN } keynum_t; +extern wic_t bindnames[]; +extern wic_t keynames[]; + +int Key_StringToKeynum (char *); +char *Key_KeynumToString (int); + void Key_Event (int key, qboolean down); void Key_Init (void); void Key_WriteBindings (QFile *f); diff --git a/include/wtoi.h b/include/wtoi.h index 1ea23ad..f9a8b9f 100644 --- a/include/wtoi.h +++ b/include/wtoi.h @@ -26,6 +26,9 @@ $Id$ */ +#ifndef WTOI_H +#define WTOI_H + typedef struct { char *name; @@ -34,3 +37,5 @@ typedef struct char *WIC_IntToStr (int, wic_t *); int WIC_StrToInt (char *, wic_t *); + +#endif // WTOI_H diff --git a/source/console.c b/source/console.c index d8f810b..a3bb6d9 100644 --- a/source/console.c +++ b/source/console.c @@ -650,7 +650,7 @@ Con_Insert_Char_f(void) Con_Printf("usage: con_insert_char \n"); return; } - key = *Cmd_Argv(1); + key = Key_StringToKeynum(Cmd_Argv(1)); if (key < 32 || key > 127) return; // non printable @@ -858,12 +858,20 @@ Con_Init */ void Con_Init (void) { + int i; + con_debuglog = COM_CheckParm("-condebug"); con = &con_main; con_linewidth = -1; Con_CheckResize (); + for (i=0 ; i<32 ; i++) { + key_lines[i][0] = ']'; + key_lines[i][1] = 0; + } + key_linepos = 1; + Con_Printf ("Console initialized.\n"); // @@ -887,8 +895,8 @@ void Con_Init (void) Cmd_AddCommand ("con_delete_char", Con_Delete_Char_f); Cmd_AddCommand ("con_cursor_left", Con_Cursor_Left_f); Cmd_AddCommand ("con_cursor_right", Con_Cursor_Right_f); - Cmd_AddCommand ("con_curser_up", Con_Cursor_Up_f); - Cmd_AddCommand ("con_curser_down", Con_Cursor_Down_f); + Cmd_AddCommand ("con_cursor_up", Con_Cursor_Up_f); + Cmd_AddCommand ("con_cursor_down", Con_Cursor_Down_f); Cmd_AddCommand ("con_page_up", Con_Page_Up_f); Cmd_AddCommand ("con_page_down", Con_Page_Down_f); Cmd_AddCommand ("con_beginningofbuffer", Con_BeginningOfBuffer_f); diff --git a/source/keys.c b/source/keys.c index 8dbe9a0..cad1af6 100644 --- a/source/keys.c +++ b/source/keys.c @@ -66,7 +66,7 @@ qboolean keydown[256]; bind_states bind_state = BIND_CONSOLE; -static wic_t bindnames[] = +wic_t bindnames[] = { { "GAME", BIND_GAME }, { "CONSOLE", BIND_CONSOLE }, @@ -74,7 +74,7 @@ static wic_t bindnames[] = { NULL, 0 } }; -static wic_t keynames[] = +wic_t keynames[] = { {"TAB", K_TAB}, {"ENTER", K_ENTER}, @@ -192,6 +192,7 @@ static wic_t keynames[] = {"MWHEELDOWN", K_MWHEELDOWN}, {"SEMICOLON", ';'}, // because a raw semicolon seperates commands + {"DOUBLEQUOTE", '"'}, {NULL,0} }; @@ -463,6 +464,17 @@ Key_Init ( void ) Cmd_AddCommand ("unbindall", Key_Unbindall_f); } +char * +bind_get(int key, bind_states state) +{ + if (bindings[state][key]) + return bindings[state][key]; + else if (bindings[BIND_ALL][key]) + return bindings[BIND_ALL][key]; + else + return NULL; +} + /* =================== Key_Event @@ -474,14 +486,26 @@ Should NOT be called during an interrupt! void Key_Event ( int key, qboolean down ) { - char *kb; + char *kb = NULL; char cmd[1024]; -// Con_Printf ("%i : %i\n", key, down); //@@@ + // Check to see if this is just a repeat. + if (down == keydown[key]) + return; keydown[key] = down; - if ((kb = bindings[bind_state][key]) || (kb = bindings[BIND_ALL][key])) { + if (keydown[K_SHIFT]) { + int shifted = keyshift[key]; + + if ((kb = bind_get(shifted, bind_state))) + key = shifted; + } + + if (!kb) + kb = bind_get(key, bind_state); + + if (kb) { if (kb[0] == '+') { // button commands add keynum as a parm snprintf (cmd, sizeof(cmd), "%s %i\n", kb, key); if (!down) diff --git a/source/menu.c b/source/menu.c index e6a843c..89257f0 100644 --- a/source/menu.c +++ b/source/menu.c @@ -646,7 +646,7 @@ void M_Options_Key (int k) //============================================================================= /* KEYS MENU */ -static char *bindnames[][2] = +static char *menu_bindnames[][2] = { {"+attack", "attack"}, {"impulse 10", "change weapon"}, @@ -668,7 +668,7 @@ static char *bindnames[][2] = {"+movedown", "swim down"} }; -#define NUMCOMMANDS (sizeof(bindnames)/sizeof(bindnames[0])) +#define NUMCOMMANDS (sizeof(menu_bindnames)/sizeof(menu_bindnames[0])) int keys_cursor; int bind_grab; @@ -751,11 +751,11 @@ void M_Keys_Draw (void) { y = 48 + 8*i; - M_Print (16, y, bindnames[i][1]); + M_Print (16, y, menu_bindnames[i][1]); - l = strlen (bindnames[i][0]); + l = strlen (menu_bindnames[i][0]); - M_FindKeysForCommand (bindnames[i][0], keys); + M_FindKeysForCommand (menu_bindnames[i][0], keys); if (keys[0] == -1) { @@ -795,7 +795,7 @@ void M_Keys_Key (int k) } else if (k != '`') { - snprintf (cmd, sizeof(cmd), "bind %s \"%s\"\n", Key_KeynumToString (k), bindnames[keys_cursor][0]); + snprintf (cmd, sizeof(cmd), "bind %s \"%s\"\n", Key_KeynumToString (k), menu_bindnames[keys_cursor][0]); Cbuf_InsertText (cmd); } @@ -826,17 +826,17 @@ void M_Keys_Key (int k) break; case K_ENTER: // go into bind mode - M_FindKeysForCommand (bindnames[keys_cursor][0], keys); + M_FindKeysForCommand (menu_bindnames[keys_cursor][0], keys); S_LocalSound ("misc/menu2.wav"); if (keys[1] != -1) - M_UnbindCommand (bindnames[keys_cursor][0]); + M_UnbindCommand (menu_bindnames[keys_cursor][0]); bind_grab = true; break; case K_BACKSPACE: // delete bindings case K_DEL: // delete bindings S_LocalSound ("misc/menu2.wav"); - M_UnbindCommand (bindnames[keys_cursor][0]); + M_UnbindCommand (menu_bindnames[keys_cursor][0]); break; } }