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];
40 char history_savedline[MAX_INPUTLINE];
42 static void Key_History_Init()
44 qfile_t *historyfile = FS_OpenRealFile("darkplaces_history.txt", "r", false);
47 char buf[MAX_INPUTLINE];
55 c = FS_Getc(historyfile);
56 if(c < 0 || c == 0 || c == '\r' || c == '\n')
61 Con_AddLine(buf, bufpos, CON_MASK_INPUT);
69 if(bufpos < MAX_INPUTLINE - 1)
74 FS_Close(historyfile);
80 static void Key_History_Shutdown()
82 // TODO write history to a file
84 qfile_t *historyfile = FS_OpenRealFile("darkplaces_history.txt", "w", false);
88 while((l = Con_FindNextLine(CON_MASK_INPUT, 0, l)) != -1)
89 FS_Printf(historyfile, "%s\n", Con_GetLine(l) + 1); // +1: skip the ]
90 FS_Close(historyfile);
94 static void Key_History_Push()
98 mask = CON_MASK_INPUT;
99 if(!key_line[1]) // empty?
101 if(!strcmp(key_line, "]quit")) // putting these into the history just sucks
103 if(!strncmp(key_line, "]quit ", 6)) // putting these into the history just sucks
105 Con_AddLine(key_line, strlen(key_line), mask);
106 Con_PrintNotToHistory(key_line); // don't mark empty lines as history
107 Con_PrintNotToHistory("\n");
111 static void Key_History_Up()
115 if(history_line >= 0)
117 history_line = Con_GetLineByID(history_line_idx);
118 if(history_line == -1)
119 history_line = -2; // -2 means before first
122 // invalid history line? bad
123 if(history_line == -2)
126 if(history_line == -1) // editing the "new" line
127 strlcpy(history_savedline, key_line, sizeof(history_savedline));
128 l = Con_FindPrevLine(CON_MASK_INPUT, 0, history_line);
132 history_line_idx = Con_GetLineID(l);
133 strlcpy(key_line, Con_GetLine(history_line), sizeof(key_line));
136 key_linepos = strlen(key_line);
139 static void Key_History_Down()
143 if(history_line >= 0)
145 history_line = Con_GetLineByID(history_line_idx);
146 if(history_line == -1)
147 history_line = -2; // -2 means before first
150 if(history_line == -1) // editing the "new" line
153 // invalid history line? take the first line then
154 if(history_line == -2)
155 history_line = -1; // next Con_FindNextLine will fix it
157 l = Con_FindNextLine(CON_MASK_INPUT, 0, history_line);
161 history_line_idx = Con_GetLineID(l);
162 strlcpy(key_line, Con_GetLine(history_line), sizeof(key_line));
167 strlcpy(key_line, history_savedline, sizeof(key_line));
170 key_linepos = strlen(key_line);
173 static int key_bmap, key_bmap2;
174 static unsigned char keydown[MAX_KEYS]; // 0 = up, 1 = down, 2 = repeating
176 typedef struct keyname_s
183 static const keyname_t keynames[] = {
186 {"ESCAPE", K_ESCAPE},
189 // spacer so it lines up with keys.h
191 {"BACKSPACE", K_BACKSPACE},
192 {"UPARROW", K_UPARROW},
193 {"DOWNARROW", K_DOWNARROW},
194 {"LEFTARROW", K_LEFTARROW},
195 {"RIGHTARROW", K_RIGHTARROW},
223 {"NUMLOCK", K_NUMLOCK},
224 {"CAPSLOCK", K_CAPSLOCK},
225 {"SCROLLOCK", K_SCROLLOCK},
227 {"KP_INS", K_KP_INS },
229 {"KP_END", K_KP_END },
231 {"KP_DOWNARROW", K_KP_DOWNARROW },
233 {"KP_PGDN", K_KP_PGDN },
235 {"KP_LEFTARROW", K_KP_LEFTARROW },
238 {"KP_RIGHTARROW", K_KP_RIGHTARROW },
240 {"KP_HOME", K_KP_HOME },
242 {"KP_UPARROW", K_KP_UPARROW },
244 {"KP_PGUP", K_KP_PGUP },
246 {"KP_DEL", K_KP_DEL },
247 {"KP_PERIOD", K_KP_PERIOD},
248 {"KP_SLASH", K_KP_SLASH },
249 {"KP_DIVIDE", K_KP_DIVIDE},
250 {"KP_MULTIPLY", K_KP_MULTIPLY},
251 {"KP_MINUS", K_KP_MINUS},
252 {"KP_PLUS", K_KP_PLUS},
253 {"KP_ENTER", K_KP_ENTER},
254 {"KP_EQUALS", K_KP_EQUALS},
258 {"MOUSE1", K_MOUSE1},
260 {"MOUSE2", K_MOUSE2},
261 {"MOUSE3", K_MOUSE3},
262 {"MWHEELUP", K_MWHEELUP},
263 {"MWHEELDOWN", K_MWHEELDOWN},
264 {"MOUSE4", K_MOUSE4},
265 {"MOUSE5", K_MOUSE5},
266 {"MOUSE6", K_MOUSE6},
267 {"MOUSE7", K_MOUSE7},
268 {"MOUSE8", K_MOUSE8},
269 {"MOUSE9", K_MOUSE9},
270 {"MOUSE10", K_MOUSE10},
271 {"MOUSE11", K_MOUSE11},
272 {"MOUSE12", K_MOUSE12},
273 {"MOUSE13", K_MOUSE13},
274 {"MOUSE14", K_MOUSE14},
275 {"MOUSE15", K_MOUSE15},
276 {"MOUSE16", K_MOUSE16},
336 {"SEMICOLON", ';'}, // because a raw semicolon separates commands
340 {"APOSTROPHE", '\''},
341 {"BACKSLASH", '\\'}, // because a raw backslash is used for special characters
347 ==============================================================================
349 LINE TYPING INTO THE CONSOLE
351 ==============================================================================
355 Key_ClearEditLine (int edit_line)
357 memset (key_line, '\0', sizeof(key_line));
364 Interactive line editing and console scrollback
368 Key_Console (int key, int ascii)
370 // LordHavoc: copied most of this from Q2 to improve keyboard handling
397 case K_KP_RIGHTARROW:
417 if ((toupper(key) == 'V' && keydown[K_CTRL]) || ((key == K_INS || key == K_KP_INS) && keydown[K_SHIFT]))
420 if ((cbd = Sys_GetClipboardData()) != 0)
427 if (*p == '\n' || *p == '\r' || *p == '\b')
435 strtok(cbd, "\n\r\b");
437 i = (int)strlen(cbd);
438 if (i + key_linepos >= MAX_INPUTLINE)
439 i= MAX_INPUTLINE - key_linepos - 1;
442 // terencehill: insert the clipboard text between the characters of the line
443 char *temp = Z_Malloc(MAX_INPUTLINE);
446 if ( key_linepos < (int)strlen(key_line) )
447 strlcpy(temp, key_line + key_linepos, (int)strlen(key_line) - key_linepos +1);
448 key_line[key_linepos] = 0;
449 strlcat(key_line, cbd, sizeof(key_line));
451 strlcat(key_line, temp, sizeof(key_line));
464 Cbuf_AddText ("clear\n");
469 if (key == K_ENTER || key == K_KP_ENTER)
471 Cbuf_AddText (key_line+1); // skip the ]
475 key_line[1] = 0; // EvilTypeGuy: null terminate
477 // force an update, because the command may take some time
478 if (cls.state == ca_disconnected)
485 // Enhanced command completion
486 // by EvilTypeGuy eviltypeguy@qeradiant.com
487 // Thanks to Fett, Taniwha
488 Con_CompleteCommandLine();
492 // Advanced Console Editing by Radix radix@planetquake.com
493 // Added/Modified by EvilTypeGuy eviltypeguy@qeradiant.com
495 // Enhanced by terencehill
497 // move cursor to the previous character
498 if (key == K_LEFTARROW || key == K_KP_LEFTARROW)
502 if(keydown[K_CTRL]) // move cursor to the previous word
511 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
514 key_linepos = pos + 1;
516 else if(keydown[K_SHIFT]) // move cursor to the previous character ignoring colors
521 if(pos-1 > 0 && key_line[pos-1] == STRING_COLOR_TAG && isdigit(key_line[pos]))
523 else if(pos-4 > 0 && key_line[pos-4] == STRING_COLOR_TAG && key_line[pos-3] == STRING_COLOR_RGB_TAG_CHAR
524 && isxdigit(key_line[pos-2]) && isxdigit(key_line[pos-1]) && isxdigit(key_line[pos]))
531 key_linepos = pos + 1;
538 // delete char before cursor
539 if (key == K_BACKSPACE || (key == 'h' && keydown[K_CTRL]))
543 strlcpy(key_line + key_linepos - 1, key_line + key_linepos, sizeof(key_line) + 1 - key_linepos);
549 // delete char on cursor
550 if (key == K_DEL || key == K_KP_DEL)
553 linelen = strlen(key_line);
554 if (key_linepos < (int)linelen)
555 memmove(key_line + key_linepos, key_line + key_linepos + 1, linelen - key_linepos);
560 // move cursor to the next character
561 if (key == K_RIGHTARROW || key == K_KP_RIGHTARROW)
563 if (key_linepos >= (int)strlen(key_line))
565 if(keydown[K_CTRL]) // move cursor to the next word
569 len = (int)strlen(key_line);
574 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
579 else if(keydown[K_SHIFT]) // move cursor to the next character ignoring colors
582 len = (int)strlen(key_line);
584 // check if there is a color tag right after the cursor
585 if (key_line[pos] == STRING_COLOR_TAG)
587 if(isdigit(key_line[pos+1]))
589 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]))
594 // now go beyond all next consecutive color tags, if any
596 while (key_line[pos] == STRING_COLOR_TAG)
598 if(isdigit(key_line[pos+1]))
600 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]))
612 if (key == K_INS || key == K_KP_INS) // toggle insert mode
618 // End Advanced Console Editing
620 if (key == K_UPARROW || key == K_KP_UPARROW || (key == 'p' && keydown[K_CTRL]))
626 if (key == K_DOWNARROW || key == K_KP_DOWNARROW || (key == 'n' && keydown[K_CTRL]))
632 if (key == K_PGUP || key == K_KP_PGUP || key == K_MWHEELUP)
639 con_backscroll += ((int) vid_conheight.integer >> 5);
643 if (key == K_PGDN || key == K_KP_PGDN || key == K_MWHEELDOWN)
650 con_backscroll -= ((int) vid_conheight.integer >> 5);
654 if (key == K_HOME || key == K_KP_HOME)
657 con_backscroll = INT_MAX;
663 if (key == K_END || key == K_KP_END)
668 key_linepos = (int)strlen(key_line);
676 if (key_linepos < MAX_INPUTLINE-1)
679 len = (int)strlen(&key_line[key_linepos]);
680 // check insert mode, or always insert if at end of line
681 if (key_insert || len == 0)
683 // can't use strcpy to move string to right
685 memmove(&key_line[key_linepos + 1], &key_line[key_linepos], len);
687 key_line[key_linepos] = ascii;
692 //============================================================================
695 char chat_buffer[MAX_INPUTLINE];
696 unsigned int chat_bufferlen = 0;
698 extern int Nicks_CompleteChatLine(char *buffer, size_t size, unsigned int pos);
701 Key_Message (int key, int ascii)
704 if (key == K_ENTER || ascii == 10 || ascii == 13)
707 Cmd_ExecuteString(chat_buffer, src_command); // not Cbuf_AddText to allow semiclons in args; however, this allows no variables then. Use aliases!
709 Cmd_ForwardStringToServer(va("%s %s", chat_mode ? "say_team" : "say ", chat_buffer));
717 // TODO add support for arrow keys and simple editing
719 if (key == K_ESCAPE) {
726 if (key == K_BACKSPACE) {
727 if (chat_bufferlen) {
729 chat_buffer[chat_bufferlen] = 0;
735 chat_bufferlen = Nicks_CompleteChatLine(chat_buffer, sizeof(chat_buffer), chat_bufferlen);
739 if (chat_bufferlen == sizeof (chat_buffer) - 1)
743 return; // non printable
745 chat_buffer[chat_bufferlen++] = ascii;
746 chat_buffer[chat_bufferlen] = 0;
749 //============================================================================
754 Returns a key number to be used to index keybindings[] by looking at
755 the given string. Single ascii characters return themselves, while
756 the K_* names are matched up.
760 Key_StringToKeynum (const char *str)
767 return tolower(str[0]);
769 for (kn = keynames; kn->name; kn++) {
770 if (!strcasecmp (str, kn->name))
778 Returns a string (either a single ascii char, or a K_* name) for the
780 FIXME: handle quote special (general escape sequence?)
784 Key_KeynumToString (int keynum)
787 static char tinystr[2];
789 // -1 is an invalid code
791 return "<KEY NOT FOUND>";
793 // search overrides first, because some characters are special
794 for (kn = keynames; kn->name; kn++)
795 if (keynum == kn->keynum)
798 // if it is printable, output it as a single character
799 if (keynum > 32 && keynum < 256)
806 // if it is not overridden and not printable, we don't know what to do with it
807 return "<UNKNOWN KEYNUM>";
812 Key_SetBinding (int keynum, int bindmap, const char *binding)
817 if (keynum == -1 || keynum >= MAX_KEYS)
821 if (keybindings[bindmap][keynum]) {
822 Z_Free (keybindings[bindmap][keynum]);
823 keybindings[bindmap][keynum] = NULL;
825 if(!binding[0]) // make "" binds be removed --blub
827 // allocate memory for new binding
828 l = strlen (binding);
829 newbinding = (char *)Z_Malloc (l + 1);
830 memcpy (newbinding, binding, l + 1);
832 keybindings[bindmap][keynum] = newbinding;
836 Key_In_Unbind_f (void)
839 char *errchar = NULL;
841 if (Cmd_Argc () != 3) {
842 Con_Print("in_unbind <bindmap> <key> : remove commands from a key\n");
846 m = strtol(Cmd_Argv (1), &errchar, 0);
847 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
848 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
852 b = Key_StringToKeynum (Cmd_Argv (2));
854 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (2));
858 Key_SetBinding (b, m, "");
865 char cmd[MAX_INPUTLINE];
866 char *errchar = NULL;
870 if (c != 3 && c != 4) {
871 Con_Print("in_bind <bindmap> <key> [command] : attach a command to a key\n");
875 m = strtol(Cmd_Argv (1), &errchar, 0);
876 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
877 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
881 b = Key_StringToKeynum (Cmd_Argv (2));
882 if (b == -1 || b >= MAX_KEYS) {
883 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (2));
888 if (keybindings[m][b])
889 Con_Printf("\"%s\" = \"%s\"\n", Cmd_Argv (2), keybindings[m][b]);
891 Con_Printf("\"%s\" is not bound\n", Cmd_Argv (2));
894 // copy the rest of the command line
895 cmd[0] = 0; // start out with a null string
896 for (i = 3; i < c; i++) {
897 strlcat (cmd, Cmd_Argv (i), sizeof (cmd));
899 strlcat (cmd, " ", sizeof (cmd));
902 Key_SetBinding (b, m, cmd);
906 Key_In_Bindmap_f (void)
909 char *errchar = NULL;
914 Con_Print("in_bindmap <bindmap> <fallback>: set current bindmap and fallback\n");
918 m1 = strtol(Cmd_Argv (1), &errchar, 0);
919 if ((m1 < 0) || (m1 >= 8) || (errchar && *errchar)) {
920 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
924 m2 = strtol(Cmd_Argv (2), &errchar, 0);
925 if ((m2 < 0) || (m2 >= 8) || (errchar && *errchar)) {
926 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(2));
939 if (Cmd_Argc () != 2) {
940 Con_Print("unbind <key> : remove commands from a key\n");
944 b = Key_StringToKeynum (Cmd_Argv (1));
946 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (1));
950 Key_SetBinding (b, 0, "");
954 Key_Unbindall_f (void)
958 for (j = 0; j < 8; j++)
959 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
960 if (keybindings[j][i])
961 Key_SetBinding (i, j, "");
965 Key_PrintBindList(int j)
967 char bindbuf[MAX_INPUTLINE];
971 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
973 p = keybindings[j][i];
976 Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\");
978 Con_Printf("^2%s ^7= \"%s\"\n", Key_KeynumToString (i), bindbuf);
980 Con_Printf("^3bindmap %d: ^2%s ^7= \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
986 Key_In_BindList_f (void)
989 char *errchar = NULL;
993 m = strtol(Cmd_Argv(1), &errchar, 0);
994 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
995 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
998 Key_PrintBindList(m);
1002 for (m = 0; m < MAX_BINDMAPS; m++)
1003 Key_PrintBindList(m);
1008 Key_BindList_f (void)
1010 Key_PrintBindList(0);
1017 char cmd[MAX_INPUTLINE];
1021 if (c != 2 && c != 3) {
1022 Con_Print("bind <key> [command] : attach a command to a key\n");
1025 b = Key_StringToKeynum (Cmd_Argv (1));
1026 if (b == -1 || b >= MAX_KEYS) {
1027 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (1));
1032 if (keybindings[0][b])
1033 Con_Printf("\"%s\" = \"%s\"\n", Cmd_Argv (1), keybindings[0][b]);
1035 Con_Printf("\"%s\" is not bound\n", Cmd_Argv (1));
1038 // copy the rest of the command line
1039 cmd[0] = 0; // start out with a null string
1040 for (i = 2; i < c; i++) {
1041 strlcat (cmd, Cmd_Argv (i), sizeof (cmd));
1043 strlcat (cmd, " ", sizeof (cmd));
1046 Key_SetBinding (b, 0, cmd);
1051 Writes lines containing "bind key value"
1055 Key_WriteBindings (qfile_t *f)
1058 char bindbuf[MAX_INPUTLINE];
1061 for (j = 0; j < MAX_BINDMAPS; j++)
1063 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
1065 p = keybindings[j][i];
1068 Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\");
1070 FS_Printf(f, "bind %s \"%s\"\n", Key_KeynumToString (i), bindbuf);
1072 FS_Printf(f, "in_bind %d %s \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
1088 // register our functions
1090 Cmd_AddCommand ("in_bind", Key_In_Bind_f, "binds a command to the specified key in the selected bindmap");
1091 Cmd_AddCommand ("in_unbind", Key_In_Unbind_f, "removes command on the specified key in the selected bindmap");
1092 Cmd_AddCommand ("in_bindlist", Key_In_BindList_f, "bindlist: displays bound keys for all bindmaps, or the given bindmap");
1093 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");
1095 Cmd_AddCommand ("bind", Key_Bind_f, "binds a command to the specified key in bindmap 0");
1096 Cmd_AddCommand ("unbind", Key_Unbind_f, "removes a command on the specified key in bindmap 0");
1097 Cmd_AddCommand ("bindlist", Key_BindList_f, "bindlist: displays bound keys for bindmap 0 bindmaps");
1098 Cmd_AddCommand ("unbindall", Key_Unbindall_f, "removes all commands from all keys in all bindmaps (leaving only shift-escape and escape)");
1100 Cvar_RegisterVariable (&con_closeontoggleconsole);
1106 Key_History_Shutdown();
1109 const char *Key_GetBind (int key)
1112 if (key < 0 || key >= MAX_KEYS)
1114 bind = keybindings[key_bmap][key];
1116 bind = keybindings[key_bmap2][key];
1120 qboolean CL_VM_InputEvent (qboolean down, int key, int ascii);
1124 Called by the system between frames for both key up and key down events
1125 Should NOT be called during an interrupt!
1128 static char tbl_keyascii[MAX_KEYS];
1129 static keydest_t tbl_keydest[MAX_KEYS];
1132 Key_Event (int key, int ascii, qboolean down)
1136 keydest_t keydest = key_dest;
1138 if (key < 0 || key >= MAX_KEYS)
1142 bind = keybindings[key_bmap][key];
1144 bind = keybindings[key_bmap2][key];
1146 if (developer.integer >= 1000)
1147 Con_Printf("Key_Event(%i, '%c', %s) keydown %i bind \"%s\"\n", key, ascii, down ? "down" : "up", keydown[key], bind ? bind : "");
1149 if(key_consoleactive)
1150 keydest = key_console;
1154 // increment key repeat count each time a down is received so that things
1155 // which want to ignore key repeat can ignore it
1156 keydown[key] = min(keydown[key] + 1, 2);
1157 if(keydown[key] == 1) {
1158 tbl_keyascii[key] = ascii;
1159 tbl_keydest[key] = keydest;
1161 ascii = tbl_keyascii[key];
1162 keydest = tbl_keydest[key];
1167 // clear repeat count now that the key is released
1169 keydest = tbl_keydest[key];
1170 ascii = tbl_keyascii[key];
1173 if(keydest == key_void)
1176 // key_consoleactive is a flag not a key_dest because the console is a
1177 // high priority overlay ontop of the normal screen (designed as a safety
1178 // feature so that developers and users can rescue themselves from a bad
1181 // this also means that toggling the console on/off does not lose the old
1184 // specially handle escape (togglemenu) and shift-escape (toggleconsole)
1185 // engine bindings, these are not handled as normal binds so that the user
1186 // can recover from a completely empty bindmap
1187 if (key == K_ESCAPE)
1189 // ignore key repeats on escape
1190 if (keydown[key] > 1)
1193 // escape does these things:
1194 // key_consoleactive - close console
1195 // key_message - abort messagemode
1196 // key_menu - go to parent menu (or key_game)
1197 // key_game - open menu
1199 // in all modes shift-escape toggles console
1200 if (keydown[K_SHIFT])
1204 Con_ToggleConsole_f ();
1205 tbl_keydest[key] = key_void; // esc release should go nowhere (especially not to key_menu or key_game)
1215 if(key_consoleactive & KEY_CONSOLEACTIVE_FORCED)
1217 key_consoleactive &= ~KEY_CONSOLEACTIVE_USER;
1221 Con_ToggleConsole_f();
1227 Key_Message (key, ascii); // that'll close the message input
1231 case key_menu_grabbed:
1232 MR_KeyEvent (key, ascii, down);
1236 // csqc has priority over toggle menu if it wants to (e.g. handling escape for UI stuff in-game.. :sick:)
1237 q = CL_VM_InputEvent(down, key, ascii);
1243 Con_Printf ("Key_Event: Bad key_dest\n");
1248 // send function keydowns to interpreter no matter what mode is (unless the menu has specifically grabbed the keyboard, for rebinding keys)
1249 if (keydest != key_menu_grabbed)
1250 if (key >= K_F1 && key <= K_F12)
1254 if(keydown[key] == 1 && down)
1256 // button commands add keynum as a parm
1258 Cbuf_AddText (va("%s %i\n", bind, key));
1261 Cbuf_AddText (bind);
1262 Cbuf_AddText ("\n");
1264 } else if(bind[0] == '+' && !down && keydown[key] == 0)
1265 Cbuf_AddText(va("-%s %i\n", bind + 1, key));
1270 // send input to console if it wants it
1271 if (keydest == key_console)
1275 // con_closeontoggleconsole enables toggleconsole keys to close the
1276 // console, as long as they are not the color prefix character
1277 // (special exemption for german keyboard layouts)
1278 if (con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && (key_consoleactive & KEY_CONSOLEACTIVE_USER) && ascii != STRING_COLOR_TAG)
1280 Con_ToggleConsole_f ();
1283 Key_Console (key, ascii);
1287 // handle toggleconsole in menu too
1288 if (keydest == key_menu)
1290 if (down && con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && ascii != STRING_COLOR_TAG)
1292 Con_ToggleConsole_f ();
1293 tbl_keydest[key] = key_void; // key release should go nowhere (especially not to key_menu or key_game)
1298 // ignore binds while a video is played, let the video system handle the key event
1299 if (cl_videoplaying)
1301 CL_Video_KeyEvent (key, ascii, keydown[key] != 0);
1305 // anything else is a key press into the game, chat line, or menu
1310 Key_Message (key, ascii);
1313 case key_menu_grabbed:
1314 MR_KeyEvent (key, ascii, down);
1317 q = CL_VM_InputEvent(down, key, ascii);
1318 // ignore key repeats on binds and only send the bind if the event hasnt been already processed by csqc
1321 if(keydown[key] == 1 && down)
1323 // button commands add keynum as a parm
1325 Cbuf_AddText (va("%s %i\n", bind, key));
1328 Cbuf_AddText (bind);
1329 Cbuf_AddText ("\n");
1331 } else if(bind[0] == '+' && !down && keydown[key] == 0)
1332 Cbuf_AddText(va("-%s %i\n", bind + 1, key));
1336 Con_Printf ("Key_Event: Bad key_dest\n");
1346 Key_ClearStates (void)
1348 memset(keydown, 0, sizeof(keydown));