]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - keys.c
added a developer 1000 print for every key event received, attempting to
[xonotic/darkplaces.git] / keys.c
diff --git a/keys.c b/keys.c
index 0f40462a694bd9072481c096457cac8efc89b672..02a1a0d9d31f04d26db550e056dc031daff4900f 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -23,6 +23,8 @@
 #include "quakedef.h"
 #include "cl_video.h"
 
+cvar_t con_closeontoggleconsole = {CVAR_SAVE, "con_closeontoggleconsole","1", "allows toggleconsole binds to close the console as well"};
+
 /*
 key up events are sent even if in console mode
 */
@@ -187,11 +189,12 @@ static const keyname_t   keynames[] = {
        {"AUX31", K_AUX31},
        {"AUX32", K_AUX32},
 
-       {"SEMICOLON", ';'},                     // because a raw semicolon seperates commands
+       {"SEMICOLON", ';'},                     // because a raw semicolon separates commands
        {"TILDE", '~'},
        {"BACKQUOTE", '`'},
        {"QUOTE", '"'},
        {"APOSTROPHE", '\''},
+       {"BACKSLASH", '\\'},            // because a raw backslash is used for special characters
 
        {NULL, 0}
 };
@@ -302,6 +305,8 @@ Key_Console (int key, char ascii)
                Cbuf_AddText (key_lines[edit_line]+1);  // skip the ]
                Cbuf_AddText ("\n");
                Con_Printf("%s\n",key_lines[edit_line]);
+               if(key_lines[edit_line][1] == 0) // empty line (just a ])?
+                       return; // no, no, you can't submit empty lines to the history...
                // LordHavoc: redesigned edit_line/history_line
                edit_line = 31;
                history_line = edit_line;
@@ -414,7 +419,7 @@ Key_Console (int key, char ascii)
                {
                        size_t linelen;
                        history_line--;
-                       linelen = strlen(key_lines[edit_line]);
+                       linelen = strlen(key_lines[history_line]);
                        memcpy(key_lines[edit_line], key_lines[history_line], linelen + 1);
                        key_linepos = (int)linelen;
                }
@@ -434,7 +439,7 @@ Key_Console (int key, char ascii)
                else
                {
                        size_t linelen;
-                       linelen = strlen(key_lines[edit_line]);
+                       linelen = strlen(key_lines[history_line]);
                        memcpy(key_lines[edit_line], key_lines[history_line], linelen + 1);
                        key_linepos = (int)linelen;
                }
@@ -505,7 +510,7 @@ static void
 Key_Message (int key, char ascii)
 {
 
-       if (key == K_ENTER)
+       if (key == K_ENTER || ascii == 10 || ascii == 13)
        {
                Cmd_ForwardStringToServer(va("%s %s", chat_team ? "say_team" : "say ", chat_buffer));
 
@@ -580,18 +585,24 @@ Key_KeynumToString (int keynum)
        const keyname_t  *kn;
        static char tinystr[2];
 
-       if (keynum == -1)
+       // -1 is an invalid code
+       if (keynum < 0)
                return "<KEY NOT FOUND>";
-       if (keynum > 32 && keynum < 127) {      // printable ascii
-               tinystr[0] = keynum;
-               tinystr[1] = 0;
-               return tinystr;
-       }
 
+       // search overrides first, because some characters are special
        for (kn = keynames; kn->name; kn++)
                if (keynum == kn->keynum)
                        return kn->name;
 
+       // if it is printable, output it as a single character
+       if (keynum > 32 && keynum < 256)
+       {
+               tinystr[0] = keynum;
+               tinystr[1] = 0;
+               return tinystr;
+       }
+
+       // if it is not overridden and not printable, we don't know what to do with it
        return "<UNKNOWN KEYNUM>";
 }
 
@@ -790,16 +801,24 @@ void
 Key_WriteBindings (qfile_t *f)
 {
        int         i, j;
+       char bindbuf[MAX_INPUTLINE];
+       const char *p;
 
-       for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
-               if (keybindings[0][i])
-                       FS_Printf(f, "bind \"%s\" \"%s\"\n",
-                                       Key_KeynumToString (i), keybindings[0][i]);
-       for (j = 1; j < 8; j++)
+       for (j = 0; j < MAX_BINDMAPS; j++)
+       {
                for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
-                       if (keybindings[j][i])
-                               FS_Printf(f, "in_bind %d \"%s\" \"%s\"\n",
-                                               j, Key_KeynumToString (i), keybindings[j][i]);
+               {
+                       p = keybindings[j][i];
+                       if (p)
+                       {
+                               Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\");
+                               if (j == 0)
+                                       FS_Printf(f, "bind %s \"%s\"\n", Key_KeynumToString (i), bindbuf);
+                               else
+                                       FS_Printf(f, "in_bind %d %s \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
+                       }
+               }
+       }
 }
 
 
@@ -824,6 +843,8 @@ Key_Init (void)
        Cmd_AddCommand ("bind", Key_Bind_f, "binds a command to the specified key in bindmap 0");
        Cmd_AddCommand ("unbind", Key_Unbind_f, "removes a command on the specified key in bindmap 0");
        Cmd_AddCommand ("unbindall", Key_Unbindall_f, "removes all commands from all keys in all bindmaps (leaving only shift-escape and escape)");
+
+       Cvar_RegisterVariable (&con_closeontoggleconsole);
 }
 
 const char *Key_GetBind (int key)
@@ -859,6 +880,9 @@ Key_Event (int key, char ascii, qboolean down)
        if (!bind)
                bind = keybindings[key_bmap2][key];
 
+       if (developer.integer >= 1000)
+               Con_Printf("Key_Event(%i, '%c', %s) keydown %i bind \"%s\"\n", key, ascii, down ? "down" : "up", keydown[key], bind ? bind : "");
+
        if(key_dest == key_game)
        {
                q = CL_VM_InputEvent(!down, key);
@@ -957,13 +981,13 @@ Key_Event (int key, char ascii, qboolean down)
                return;
        }
 
-#if 1
+#if 0
        // ignore binds (other than the above escape/F1-F12 keys) while in console
        if (key_consoleactive && down)
 #else
        // respond to toggleconsole binds while in console unless the pressed key
        // happens to be the color prefix character (such as on German keyboards)
-       if (key_consoleactive && down && (strncmp(bind, "toggleconsole", strlen("toggleconsole")) || ascii == STRING_COLOR_TAG))
+       if (key_consoleactive && down && (!con_closeontoggleconsole.integer || !bind || strncmp(bind, "toggleconsole", strlen("toggleconsole")) || ascii == STRING_COLOR_TAG))
 #endif
        {
                Key_Console (key, ascii);