2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to:
18 Free Software Foundation, Inc.
19 59 Temple Place - Suite 330
20 Boston, MA 02111-1307, USA
26 cvar_t con_closeontoggleconsole = {CVAR_SAVE, "con_closeontoggleconsole","1", "allows toggleconsole binds to close the console as well"};
29 key up events are sent even if in console mode
32 char key_line[MAX_INPUTLINE];
34 qboolean key_insert = true; // insert key toggle (for editing)
36 int key_consoleactive;
37 char *keybindings[MAX_BINDMAPS][MAX_KEYS];
39 char history_savedline[MAX_INPUTLINE];
41 #define HIST_TEXTSIZE 262144
42 #define HIST_MAXLINES 4096
44 static void Key_History_Init()
47 ConBuffer_Init(&history, HIST_TEXTSIZE, HIST_MAXLINES, zonemempool);
49 historyfile = FS_OpenRealFile("darkplaces_history.txt", "rb", false); // rb to handle unix line endings on windows too
52 char buf[MAX_INPUTLINE];
59 c = FS_Getc(historyfile);
60 if(c < 0 || c == 0 || c == '\r' || c == '\n')
65 ConBuffer_AddLine(&history, buf, bufpos, 0);
73 if(bufpos < MAX_INPUTLINE - 1)
78 FS_Close(historyfile);
84 static void Key_History_Shutdown()
86 // TODO write history to a file
88 qfile_t *historyfile = FS_OpenRealFile("darkplaces_history.txt", "w", false);
92 for(i = 0; i < history.lines_count; ++i)
93 FS_Printf(historyfile, "%s\n", ConBuffer_GetLine(&history, i));
94 FS_Close(historyfile);
98 static void Key_History_Push()
100 if(key_line[1]) // empty?
101 if(strcmp(key_line, "]quit")) // putting these into the history just sucks
102 if(strncmp(key_line, "]quit ", 6)) // putting these into the history just sucks
103 ConBuffer_AddLine(&history, key_line + 1, strlen(key_line) - 1, 0);
104 Con_Printf("%s\n", key_line); // don't mark empty lines as history
108 static void Key_History_Up()
110 if(history_line == -1) // editing the "new" line
111 strlcpy(history_savedline, key_line + 1, sizeof(history_savedline));
113 if(history_line == -1)
115 history_line = history.lines_count - 1;
116 if(history_line != -1)
118 strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
119 key_linepos = strlen(key_line);
122 else if(history_line > 0)
124 --history_line; // this also does -1 -> 0, so it is good
125 strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
126 key_linepos = strlen(key_line);
130 static void Key_History_Down()
132 if(history_line == -1) // editing the "new" line
135 if(history_line < history.lines_count - 1)
138 strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
143 strlcpy(key_line + 1, history_savedline, sizeof(key_line) - 1);
146 key_linepos = strlen(key_line);
149 static int key_bmap, key_bmap2;
150 static unsigned char keydown[MAX_KEYS]; // 0 = up, 1 = down, 2 = repeating
152 typedef struct keyname_s
159 static const keyname_t keynames[] = {
162 {"ESCAPE", K_ESCAPE},
165 // spacer so it lines up with keys.h
167 {"BACKSPACE", K_BACKSPACE},
168 {"UPARROW", K_UPARROW},
169 {"DOWNARROW", K_DOWNARROW},
170 {"LEFTARROW", K_LEFTARROW},
171 {"RIGHTARROW", K_RIGHTARROW},
199 {"NUMLOCK", K_NUMLOCK},
200 {"CAPSLOCK", K_CAPSLOCK},
201 {"SCROLLOCK", K_SCROLLOCK},
203 {"KP_INS", K_KP_INS },
205 {"KP_END", K_KP_END },
207 {"KP_DOWNARROW", K_KP_DOWNARROW },
209 {"KP_PGDN", K_KP_PGDN },
211 {"KP_LEFTARROW", K_KP_LEFTARROW },
214 {"KP_RIGHTARROW", K_KP_RIGHTARROW },
216 {"KP_HOME", K_KP_HOME },
218 {"KP_UPARROW", K_KP_UPARROW },
220 {"KP_PGUP", K_KP_PGUP },
222 {"KP_DEL", K_KP_DEL },
223 {"KP_PERIOD", K_KP_PERIOD},
224 {"KP_SLASH", K_KP_SLASH },
225 {"KP_DIVIDE", K_KP_DIVIDE},
226 {"KP_MULTIPLY", K_KP_MULTIPLY},
227 {"KP_MINUS", K_KP_MINUS},
228 {"KP_PLUS", K_KP_PLUS},
229 {"KP_ENTER", K_KP_ENTER},
230 {"KP_EQUALS", K_KP_EQUALS},
234 {"MOUSE1", K_MOUSE1},
236 {"MOUSE2", K_MOUSE2},
237 {"MOUSE3", K_MOUSE3},
238 {"MWHEELUP", K_MWHEELUP},
239 {"MWHEELDOWN", K_MWHEELDOWN},
240 {"MOUSE4", K_MOUSE4},
241 {"MOUSE5", K_MOUSE5},
242 {"MOUSE6", K_MOUSE6},
243 {"MOUSE7", K_MOUSE7},
244 {"MOUSE8", K_MOUSE8},
245 {"MOUSE9", K_MOUSE9},
246 {"MOUSE10", K_MOUSE10},
247 {"MOUSE11", K_MOUSE11},
248 {"MOUSE12", K_MOUSE12},
249 {"MOUSE13", K_MOUSE13},
250 {"MOUSE14", K_MOUSE14},
251 {"MOUSE15", K_MOUSE15},
252 {"MOUSE16", K_MOUSE16},
312 {"SEMICOLON", ';'}, // because a raw semicolon separates commands
316 {"APOSTROPHE", '\''},
317 {"BACKSLASH", '\\'}, // because a raw backslash is used for special characters
323 ==============================================================================
325 LINE TYPING INTO THE CONSOLE
327 ==============================================================================
331 Key_ClearEditLine (int edit_line)
333 memset (key_line, '\0', sizeof(key_line));
340 Interactive line editing and console scrollback
344 Key_Console (int key, int ascii)
346 // LordHavoc: copied most of this from Q2 to improve keyboard handling
373 case K_KP_RIGHTARROW:
393 if ((toupper(key) == 'V' && keydown[K_CTRL]) || ((key == K_INS || key == K_KP_INS) && keydown[K_SHIFT]))
396 if ((cbd = Sys_GetClipboardData()) != 0)
403 if (*p == '\n' || *p == '\r' || *p == '\b')
411 strtok(cbd, "\n\r\b");
413 i = (int)strlen(cbd);
414 if (i + key_linepos >= MAX_INPUTLINE)
415 i= MAX_INPUTLINE - key_linepos - 1;
418 // terencehill: insert the clipboard text between the characters of the line
419 char *temp = Z_Malloc(MAX_INPUTLINE);
422 if ( key_linepos < (int)strlen(key_line) )
423 strlcpy(temp, key_line + key_linepos, (int)strlen(key_line) - key_linepos +1);
424 key_line[key_linepos] = 0;
425 strlcat(key_line, cbd, sizeof(key_line));
427 strlcat(key_line, temp, sizeof(key_line));
440 Cbuf_AddText ("clear\n");
445 if (key == K_ENTER || key == K_KP_ENTER)
447 Cbuf_AddText (key_line+1); // skip the ]
451 key_line[1] = 0; // EvilTypeGuy: null terminate
453 // force an update, because the command may take some time
454 if (cls.state == ca_disconnected)
461 // Enhanced command completion
462 // by EvilTypeGuy eviltypeguy@qeradiant.com
463 // Thanks to Fett, Taniwha
464 Con_CompleteCommandLine();
468 // Advanced Console Editing by Radix radix@planetquake.com
469 // Added/Modified by EvilTypeGuy eviltypeguy@qeradiant.com
471 // Enhanced by terencehill
473 // move cursor to the previous character
474 if (key == K_LEFTARROW || key == K_KP_LEFTARROW)
478 if(keydown[K_CTRL]) // move cursor to the previous word
487 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
490 key_linepos = pos + 1;
492 else if(keydown[K_SHIFT]) // move cursor to the previous character ignoring colors
497 if(pos-1 > 0 && key_line[pos-1] == STRING_COLOR_TAG && isdigit(key_line[pos]))
499 else if(pos-4 > 0 && key_line[pos-4] == STRING_COLOR_TAG && key_line[pos-3] == STRING_COLOR_RGB_TAG_CHAR
500 && isxdigit(key_line[pos-2]) && isxdigit(key_line[pos-1]) && isxdigit(key_line[pos]))
507 key_linepos = pos + 1;
514 // delete char before cursor
515 if (key == K_BACKSPACE || (key == 'h' && keydown[K_CTRL]))
519 strlcpy(key_line + key_linepos - 1, key_line + key_linepos, sizeof(key_line) + 1 - key_linepos);
525 // delete char on cursor
526 if (key == K_DEL || key == K_KP_DEL)
529 linelen = strlen(key_line);
530 if (key_linepos < (int)linelen)
531 memmove(key_line + key_linepos, key_line + key_linepos + 1, linelen - key_linepos);
536 // move cursor to the next character
537 if (key == K_RIGHTARROW || key == K_KP_RIGHTARROW)
539 if (key_linepos >= (int)strlen(key_line))
541 if(keydown[K_CTRL]) // move cursor to the next word
545 len = (int)strlen(key_line);
550 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
555 else if(keydown[K_SHIFT]) // move cursor to the next character ignoring colors
558 len = (int)strlen(key_line);
560 // check if there is a color tag right after the cursor
561 if (key_line[pos] == STRING_COLOR_TAG)
563 if(isdigit(key_line[pos+1]))
565 else if(key_line[pos+1] == STRING_COLOR_RGB_TAG_CHAR && isxdigit(key_line[pos+2]) && isxdigit(key_line[pos+3]) && isxdigit(key_line[pos+4]))
570 // now go beyond all next consecutive color tags, if any
572 while (key_line[pos] == STRING_COLOR_TAG)
574 if(isdigit(key_line[pos+1]))
576 else if(key_line[pos+1] == STRING_COLOR_RGB_TAG_CHAR && isxdigit(key_line[pos+2]) && isxdigit(key_line[pos+3]) && isxdigit(key_line[pos+4]))
588 if (key == K_INS || key == K_KP_INS) // toggle insert mode
594 // End Advanced Console Editing
596 if (key == K_UPARROW || key == K_KP_UPARROW || (key == 'p' && keydown[K_CTRL]))
602 if (key == K_DOWNARROW || key == K_KP_DOWNARROW || (key == 'n' && keydown[K_CTRL]))
608 if (key == K_PGUP || key == K_KP_PGUP || key == K_MWHEELUP)
615 con_backscroll += ((int) vid_conheight.integer >> 5);
619 if (key == K_PGDN || key == K_KP_PGDN || key == K_MWHEELDOWN)
626 con_backscroll -= ((int) vid_conheight.integer >> 5);
630 if (key == K_HOME || key == K_KP_HOME)
633 con_backscroll = INT_MAX;
639 if (key == K_END || key == K_KP_END)
644 key_linepos = (int)strlen(key_line);
652 if (key_linepos < MAX_INPUTLINE-1)
655 len = (int)strlen(&key_line[key_linepos]);
656 // check insert mode, or always insert if at end of line
657 if (key_insert || len == 0)
659 // can't use strcpy to move string to right
661 memmove(&key_line[key_linepos + 1], &key_line[key_linepos], len);
663 key_line[key_linepos] = ascii;
668 //============================================================================
671 char chat_buffer[MAX_INPUTLINE];
672 unsigned int chat_bufferlen = 0;
674 extern int Nicks_CompleteChatLine(char *buffer, size_t size, unsigned int pos);
677 Key_Message (int key, int ascii)
680 if (key == K_ENTER || ascii == 10 || ascii == 13)
683 Cmd_ExecuteString(chat_buffer, src_command); // not Cbuf_AddText to allow semiclons in args; however, this allows no variables then. Use aliases!
685 Cmd_ForwardStringToServer(va("%s %s", chat_mode ? "say_team" : "say ", chat_buffer));
693 // TODO add support for arrow keys and simple editing
695 if (key == K_ESCAPE) {
702 if (key == K_BACKSPACE) {
703 if (chat_bufferlen) {
705 chat_buffer[chat_bufferlen] = 0;
711 chat_bufferlen = Nicks_CompleteChatLine(chat_buffer, sizeof(chat_buffer), chat_bufferlen);
715 if (chat_bufferlen == sizeof (chat_buffer) - 1)
719 return; // non printable
721 chat_buffer[chat_bufferlen++] = ascii;
722 chat_buffer[chat_bufferlen] = 0;
725 //============================================================================
730 Returns a key number to be used to index keybindings[] by looking at
731 the given string. Single ascii characters return themselves, while
732 the K_* names are matched up.
736 Key_StringToKeynum (const char *str)
743 return tolower(str[0]);
745 for (kn = keynames; kn->name; kn++) {
746 if (!strcasecmp (str, kn->name))
754 Returns a string (either a single ascii char, or a K_* name) for the
756 FIXME: handle quote special (general escape sequence?)
760 Key_KeynumToString (int keynum)
763 static char tinystr[2];
765 // -1 is an invalid code
767 return "<KEY NOT FOUND>";
769 // search overrides first, because some characters are special
770 for (kn = keynames; kn->name; kn++)
771 if (keynum == kn->keynum)
774 // if it is printable, output it as a single character
775 if (keynum > 32 && keynum < 256)
782 // if it is not overridden and not printable, we don't know what to do with it
783 return "<UNKNOWN KEYNUM>";
788 Key_SetBinding (int keynum, int bindmap, const char *binding)
793 if (keynum == -1 || keynum >= MAX_KEYS)
797 if (keybindings[bindmap][keynum]) {
798 Z_Free (keybindings[bindmap][keynum]);
799 keybindings[bindmap][keynum] = NULL;
801 if(!binding[0]) // make "" binds be removed --blub
803 // allocate memory for new binding
804 l = strlen (binding);
805 newbinding = (char *)Z_Malloc (l + 1);
806 memcpy (newbinding, binding, l + 1);
808 keybindings[bindmap][keynum] = newbinding;
812 Key_In_Unbind_f (void)
815 char *errchar = NULL;
817 if (Cmd_Argc () != 3) {
818 Con_Print("in_unbind <bindmap> <key> : remove commands from a key\n");
822 m = strtol(Cmd_Argv (1), &errchar, 0);
823 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
824 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
828 b = Key_StringToKeynum (Cmd_Argv (2));
830 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (2));
834 Key_SetBinding (b, m, "");
841 char cmd[MAX_INPUTLINE];
842 char *errchar = NULL;
846 if (c != 3 && c != 4) {
847 Con_Print("in_bind <bindmap> <key> [command] : attach a command to a key\n");
851 m = strtol(Cmd_Argv (1), &errchar, 0);
852 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
853 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
857 b = Key_StringToKeynum (Cmd_Argv (2));
858 if (b == -1 || b >= MAX_KEYS) {
859 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (2));
864 if (keybindings[m][b])
865 Con_Printf("\"%s\" = \"%s\"\n", Cmd_Argv (2), keybindings[m][b]);
867 Con_Printf("\"%s\" is not bound\n", Cmd_Argv (2));
870 // copy the rest of the command line
871 cmd[0] = 0; // start out with a null string
872 for (i = 3; i < c; i++) {
873 strlcat (cmd, Cmd_Argv (i), sizeof (cmd));
875 strlcat (cmd, " ", sizeof (cmd));
878 Key_SetBinding (b, m, cmd);
882 Key_In_Bindmap_f (void)
885 char *errchar = NULL;
890 Con_Print("in_bindmap <bindmap> <fallback>: set current bindmap and fallback\n");
894 m1 = strtol(Cmd_Argv (1), &errchar, 0);
895 if ((m1 < 0) || (m1 >= 8) || (errchar && *errchar)) {
896 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
900 m2 = strtol(Cmd_Argv (2), &errchar, 0);
901 if ((m2 < 0) || (m2 >= 8) || (errchar && *errchar)) {
902 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(2));
915 if (Cmd_Argc () != 2) {
916 Con_Print("unbind <key> : remove commands from a key\n");
920 b = Key_StringToKeynum (Cmd_Argv (1));
922 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (1));
926 Key_SetBinding (b, 0, "");
930 Key_Unbindall_f (void)
934 for (j = 0; j < 8; j++)
935 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
936 if (keybindings[j][i])
937 Key_SetBinding (i, j, "");
941 Key_PrintBindList(int j)
943 char bindbuf[MAX_INPUTLINE];
947 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
949 p = keybindings[j][i];
952 Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\");
954 Con_Printf("^2%s ^7= \"%s\"\n", Key_KeynumToString (i), bindbuf);
956 Con_Printf("^3bindmap %d: ^2%s ^7= \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
962 Key_In_BindList_f (void)
965 char *errchar = NULL;
969 m = strtol(Cmd_Argv(1), &errchar, 0);
970 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
971 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
974 Key_PrintBindList(m);
978 for (m = 0; m < MAX_BINDMAPS; m++)
979 Key_PrintBindList(m);
984 Key_BindList_f (void)
986 Key_PrintBindList(0);
993 char cmd[MAX_INPUTLINE];
997 if (c != 2 && c != 3) {
998 Con_Print("bind <key> [command] : attach a command to a key\n");
1001 b = Key_StringToKeynum (Cmd_Argv (1));
1002 if (b == -1 || b >= MAX_KEYS) {
1003 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (1));
1008 if (keybindings[0][b])
1009 Con_Printf("\"%s\" = \"%s\"\n", Cmd_Argv (1), keybindings[0][b]);
1011 Con_Printf("\"%s\" is not bound\n", Cmd_Argv (1));
1014 // copy the rest of the command line
1015 cmd[0] = 0; // start out with a null string
1016 for (i = 2; i < c; i++) {
1017 strlcat (cmd, Cmd_Argv (i), sizeof (cmd));
1019 strlcat (cmd, " ", sizeof (cmd));
1022 Key_SetBinding (b, 0, cmd);
1027 Writes lines containing "bind key value"
1031 Key_WriteBindings (qfile_t *f)
1034 char bindbuf[MAX_INPUTLINE];
1037 for (j = 0; j < MAX_BINDMAPS; j++)
1039 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
1041 p = keybindings[j][i];
1044 Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\");
1046 FS_Printf(f, "bind %s \"%s\"\n", Key_KeynumToString (i), bindbuf);
1048 FS_Printf(f, "in_bind %d %s \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
1064 // register our functions
1066 Cmd_AddCommand ("in_bind", Key_In_Bind_f, "binds a command to the specified key in the selected bindmap");
1067 Cmd_AddCommand ("in_unbind", Key_In_Unbind_f, "removes command on the specified key in the selected bindmap");
1068 Cmd_AddCommand ("in_bindlist", Key_In_BindList_f, "bindlist: displays bound keys for all bindmaps, or the given bindmap");
1069 Cmd_AddCommand ("in_bindmap", Key_In_Bindmap_f, "selects active foreground and background (used only if a key is not bound in the foreground) bindmaps for typing");
1071 Cmd_AddCommand ("bind", Key_Bind_f, "binds a command to the specified key in bindmap 0");
1072 Cmd_AddCommand ("unbind", Key_Unbind_f, "removes a command on the specified key in bindmap 0");
1073 Cmd_AddCommand ("bindlist", Key_BindList_f, "bindlist: displays bound keys for bindmap 0 bindmaps");
1074 Cmd_AddCommand ("unbindall", Key_Unbindall_f, "removes all commands from all keys in all bindmaps (leaving only shift-escape and escape)");
1076 Cvar_RegisterVariable (&con_closeontoggleconsole);
1082 Key_History_Shutdown();
1085 const char *Key_GetBind (int key)
1088 if (key < 0 || key >= MAX_KEYS)
1090 bind = keybindings[key_bmap][key];
1092 bind = keybindings[key_bmap2][key];
1096 qboolean CL_VM_InputEvent (qboolean down, int key, int ascii);
1100 Called by the system between frames for both key up and key down events
1101 Should NOT be called during an interrupt!
1104 static char tbl_keyascii[MAX_KEYS];
1105 static keydest_t tbl_keydest[MAX_KEYS];
1108 Key_Event (int key, int ascii, qboolean down)
1112 keydest_t keydest = key_dest;
1114 if (key < 0 || key >= MAX_KEYS)
1118 bind = keybindings[key_bmap][key];
1120 bind = keybindings[key_bmap2][key];
1122 if (developer.integer >= 1000)
1123 Con_Printf("Key_Event(%i, '%c', %s) keydown %i bind \"%s\"\n", key, ascii, down ? "down" : "up", keydown[key], bind ? bind : "");
1125 if(key_consoleactive)
1126 keydest = key_console;
1130 // increment key repeat count each time a down is received so that things
1131 // which want to ignore key repeat can ignore it
1132 keydown[key] = min(keydown[key] + 1, 2);
1133 if(keydown[key] == 1) {
1134 tbl_keyascii[key] = ascii;
1135 tbl_keydest[key] = keydest;
1137 ascii = tbl_keyascii[key];
1138 keydest = tbl_keydest[key];
1143 // clear repeat count now that the key is released
1145 keydest = tbl_keydest[key];
1146 ascii = tbl_keyascii[key];
1149 if(keydest == key_void)
1152 // key_consoleactive is a flag not a key_dest because the console is a
1153 // high priority overlay ontop of the normal screen (designed as a safety
1154 // feature so that developers and users can rescue themselves from a bad
1157 // this also means that toggling the console on/off does not lose the old
1160 // specially handle escape (togglemenu) and shift-escape (toggleconsole)
1161 // engine bindings, these are not handled as normal binds so that the user
1162 // can recover from a completely empty bindmap
1163 if (key == K_ESCAPE)
1165 // ignore key repeats on escape
1166 if (keydown[key] > 1)
1169 // escape does these things:
1170 // key_consoleactive - close console
1171 // key_message - abort messagemode
1172 // key_menu - go to parent menu (or key_game)
1173 // key_game - open menu
1175 // in all modes shift-escape toggles console
1176 if (keydown[K_SHIFT])
1180 Con_ToggleConsole_f ();
1181 tbl_keydest[key] = key_void; // esc release should go nowhere (especially not to key_menu or key_game)
1191 if(key_consoleactive & KEY_CONSOLEACTIVE_FORCED)
1193 key_consoleactive &= ~KEY_CONSOLEACTIVE_USER;
1197 Con_ToggleConsole_f();
1203 Key_Message (key, ascii); // that'll close the message input
1207 case key_menu_grabbed:
1208 MR_KeyEvent (key, ascii, down);
1212 // csqc has priority over toggle menu if it wants to (e.g. handling escape for UI stuff in-game.. :sick:)
1213 q = CL_VM_InputEvent(down, key, ascii);
1219 Con_Printf ("Key_Event: Bad key_dest\n");
1224 // send function keydowns to interpreter no matter what mode is (unless the menu has specifically grabbed the keyboard, for rebinding keys)
1225 if (keydest != key_menu_grabbed)
1226 if (key >= K_F1 && key <= K_F12)
1230 if(keydown[key] == 1 && down)
1232 // button commands add keynum as a parm
1234 Cbuf_AddText (va("%s %i\n", bind, key));
1237 Cbuf_AddText (bind);
1238 Cbuf_AddText ("\n");
1240 } else if(bind[0] == '+' && !down && keydown[key] == 0)
1241 Cbuf_AddText(va("-%s %i\n", bind + 1, key));
1246 // send input to console if it wants it
1247 if (keydest == key_console)
1251 // con_closeontoggleconsole enables toggleconsole keys to close the
1252 // console, as long as they are not the color prefix character
1253 // (special exemption for german keyboard layouts)
1254 if (con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && (key_consoleactive & KEY_CONSOLEACTIVE_USER) && ascii != STRING_COLOR_TAG)
1256 Con_ToggleConsole_f ();
1259 Key_Console (key, ascii);
1263 // handle toggleconsole in menu too
1264 if (keydest == key_menu)
1266 if (down && con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && ascii != STRING_COLOR_TAG)
1268 Con_ToggleConsole_f ();
1269 tbl_keydest[key] = key_void; // key release should go nowhere (especially not to key_menu or key_game)
1274 // ignore binds while a video is played, let the video system handle the key event
1275 if (cl_videoplaying)
1277 CL_Video_KeyEvent (key, ascii, keydown[key] != 0);
1281 // anything else is a key press into the game, chat line, or menu
1286 Key_Message (key, ascii);
1289 case key_menu_grabbed:
1290 MR_KeyEvent (key, ascii, down);
1293 q = CL_VM_InputEvent(down, key, ascii);
1294 // ignore key repeats on binds and only send the bind if the event hasnt been already processed by csqc
1297 if(keydown[key] == 1 && down)
1299 // button commands add keynum as a parm
1301 Cbuf_AddText (va("%s %i\n", bind, key));
1304 Cbuf_AddText (bind);
1305 Cbuf_AddText ("\n");
1307 } else if(bind[0] == '+' && !down && keydown[key] == 0)
1308 Cbuf_AddText(va("-%s %i\n", bind + 1, key));
1312 Con_Printf ("Key_Event: Bad key_dest\n");
1322 Key_ClearStates (void)
1324 memset(keydown, 0, sizeof(keydown));