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("dp_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("dp_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 Con_AddLine(key_line, strlen(key_line), mask);
104 Con_PrintNotToHistory(key_line); // don't mark empty lines as history
105 Con_PrintNotToHistory("\n");
109 static void Key_History_Up()
113 if(history_line >= 0)
115 history_line = Con_GetLineByID(history_line_idx);
116 if(history_line == -1)
117 history_line = -2; // -2 means before first
120 // invalid history line? bad
121 if(history_line == -2)
124 if(history_line == -1) // editing the "new" line
125 strlcpy(history_savedline, key_line, sizeof(history_savedline));
126 l = Con_FindPrevLine(CON_MASK_INPUT, 0, history_line);
130 history_line_idx = Con_GetLineID(l);
131 strlcpy(key_line, Con_GetLine(history_line), sizeof(key_line));
134 key_linepos = strlen(key_line);
137 static void Key_History_Down()
141 if(history_line >= 0)
143 history_line = Con_GetLineByID(history_line_idx);
144 if(history_line == -1)
145 history_line = -2; // -2 means before first
148 if(history_line == -1) // editing the "new" line
151 // invalid history line? take the first line then
152 if(history_line == -2)
153 history_line = -1; // next Con_FindNextLine will fix it
155 l = Con_FindNextLine(CON_MASK_INPUT, 0, history_line);
159 history_line_idx = Con_GetLineID(l);
160 strlcpy(key_line, Con_GetLine(history_line), sizeof(key_line));
165 strlcpy(key_line, history_savedline, sizeof(key_line));
168 key_linepos = strlen(key_line);
171 static int key_bmap, key_bmap2;
172 static unsigned char keydown[MAX_KEYS]; // 0 = up, 1 = down, 2 = repeating
174 typedef struct keyname_s
181 static const keyname_t keynames[] = {
184 {"ESCAPE", K_ESCAPE},
187 // spacer so it lines up with keys.h
189 {"BACKSPACE", K_BACKSPACE},
190 {"UPARROW", K_UPARROW},
191 {"DOWNARROW", K_DOWNARROW},
192 {"LEFTARROW", K_LEFTARROW},
193 {"RIGHTARROW", K_RIGHTARROW},
221 {"NUMLOCK", K_NUMLOCK},
222 {"CAPSLOCK", K_CAPSLOCK},
223 {"SCROLLOCK", K_SCROLLOCK},
225 {"KP_INS", K_KP_INS },
227 {"KP_END", K_KP_END },
229 {"KP_DOWNARROW", K_KP_DOWNARROW },
231 {"KP_PGDN", K_KP_PGDN },
233 {"KP_LEFTARROW", K_KP_LEFTARROW },
236 {"KP_RIGHTARROW", K_KP_RIGHTARROW },
238 {"KP_HOME", K_KP_HOME },
240 {"KP_UPARROW", K_KP_UPARROW },
242 {"KP_PGUP", K_KP_PGUP },
244 {"KP_DEL", K_KP_DEL },
245 {"KP_PERIOD", K_KP_PERIOD},
246 {"KP_SLASH", K_KP_SLASH },
247 {"KP_DIVIDE", K_KP_DIVIDE},
248 {"KP_MULTIPLY", K_KP_MULTIPLY},
249 {"KP_MINUS", K_KP_MINUS},
250 {"KP_PLUS", K_KP_PLUS},
251 {"KP_ENTER", K_KP_ENTER},
252 {"KP_EQUALS", K_KP_EQUALS},
256 {"MOUSE1", K_MOUSE1},
258 {"MOUSE2", K_MOUSE2},
259 {"MOUSE3", K_MOUSE3},
260 {"MWHEELUP", K_MWHEELUP},
261 {"MWHEELDOWN", K_MWHEELDOWN},
262 {"MOUSE4", K_MOUSE4},
263 {"MOUSE5", K_MOUSE5},
264 {"MOUSE6", K_MOUSE6},
265 {"MOUSE7", K_MOUSE7},
266 {"MOUSE8", K_MOUSE8},
267 {"MOUSE9", K_MOUSE9},
268 {"MOUSE10", K_MOUSE10},
269 {"MOUSE11", K_MOUSE11},
270 {"MOUSE12", K_MOUSE12},
271 {"MOUSE13", K_MOUSE13},
272 {"MOUSE14", K_MOUSE14},
273 {"MOUSE15", K_MOUSE15},
274 {"MOUSE16", K_MOUSE16},
334 {"SEMICOLON", ';'}, // because a raw semicolon separates commands
338 {"APOSTROPHE", '\''},
339 {"BACKSLASH", '\\'}, // because a raw backslash is used for special characters
345 ==============================================================================
347 LINE TYPING INTO THE CONSOLE
349 ==============================================================================
353 Key_ClearEditLine (int edit_line)
355 memset (key_line, '\0', sizeof(key_line));
362 Interactive line editing and console scrollback
366 Key_Console (int key, int ascii)
368 // LordHavoc: copied most of this from Q2 to improve keyboard handling
395 case K_KP_RIGHTARROW:
415 if ((toupper(key) == 'V' && keydown[K_CTRL]) || ((key == K_INS || key == K_KP_INS) && keydown[K_SHIFT]))
418 if ((cbd = Sys_GetClipboardData()) != 0)
425 if (*p == '\n' || *p == '\r' || *p == '\b')
433 strtok(cbd, "\n\r\b");
435 i = (int)strlen(cbd);
436 if (i + key_linepos >= MAX_INPUTLINE)
437 i= MAX_INPUTLINE - key_linepos - 1;
440 // terencehill: insert the clipboard text between the characters of the line
441 char *temp = Z_Malloc(MAX_INPUTLINE);
444 if ( key_linepos < (int)strlen(key_line) )
445 strlcpy(temp, key_line + key_linepos, (int)strlen(key_line) - key_linepos +1);
446 key_line[key_linepos] = 0;
447 strlcat(key_line, cbd, sizeof(key_line));
449 strlcat(key_line, temp, sizeof(key_line));
462 Cbuf_AddText ("clear\n");
467 if (key == K_ENTER || key == K_KP_ENTER)
469 Cbuf_AddText (key_line+1); // skip the ]
473 key_line[1] = 0; // EvilTypeGuy: null terminate
475 // force an update, because the command may take some time
476 if (cls.state == ca_disconnected)
483 // Enhanced command completion
484 // by EvilTypeGuy eviltypeguy@qeradiant.com
485 // Thanks to Fett, Taniwha
486 Con_CompleteCommandLine();
490 // Advanced Console Editing by Radix radix@planetquake.com
491 // Added/Modified by EvilTypeGuy eviltypeguy@qeradiant.com
493 // Enhanced by terencehill
495 // move cursor to the previous character
496 if (key == K_LEFTARROW || key == K_KP_LEFTARROW)
500 if(keydown[K_CTRL]) // move cursor to the previous word
509 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
512 key_linepos = pos + 1;
514 else if(keydown[K_SHIFT]) // move cursor to the previous character ignoring colors
519 if(pos-1 > 0 && key_line[pos-1] == STRING_COLOR_TAG && isdigit(key_line[pos]))
521 else if(pos-4 > 0 && key_line[pos-4] == STRING_COLOR_TAG && key_line[pos-3] == STRING_COLOR_RGB_TAG_CHAR
522 && isxdigit(key_line[pos-2]) && isxdigit(key_line[pos-1]) && isxdigit(key_line[pos]))
529 key_linepos = pos + 1;
536 // delete char before cursor
537 if (key == K_BACKSPACE || (key == 'h' && keydown[K_CTRL]))
541 strlcpy(key_line + key_linepos - 1, key_line + key_linepos, sizeof(key_line) + 1 - key_linepos);
547 // delete char on cursor
548 if (key == K_DEL || key == K_KP_DEL)
551 linelen = strlen(key_line);
552 if (key_linepos < (int)linelen)
553 memmove(key_line + key_linepos, key_line + key_linepos + 1, linelen - key_linepos);
558 // move cursor to the next character
559 if (key == K_RIGHTARROW || key == K_KP_RIGHTARROW)
561 if (key_linepos >= (int)strlen(key_line))
563 if(keydown[K_CTRL]) // move cursor to the next word
567 len = (int)strlen(key_line);
572 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
577 else if(keydown[K_SHIFT]) // move cursor to the next character ignoring colors
580 len = (int)strlen(key_line);
582 // check if there is a color tag right after the cursor
583 if (key_line[pos] == STRING_COLOR_TAG)
585 if(isdigit(key_line[pos+1]))
587 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]))
592 // now go beyond all next consecutive color tags, if any
594 while (key_line[pos] == STRING_COLOR_TAG)
596 if(isdigit(key_line[pos+1]))
598 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]))
610 if (key == K_INS || key == K_KP_INS) // toggle insert mode
616 // End Advanced Console Editing
618 if (key == K_UPARROW || key == K_KP_UPARROW || (key == 'p' && keydown[K_CTRL]))
624 if (key == K_DOWNARROW || key == K_KP_DOWNARROW || (key == 'n' && keydown[K_CTRL]))
630 if (key == K_PGUP || key == K_KP_PGUP || key == K_MWHEELUP)
637 con_backscroll += ((int) vid_conheight.integer >> 5);
641 if (key == K_PGDN || key == K_KP_PGDN || key == K_MWHEELDOWN)
648 con_backscroll -= ((int) vid_conheight.integer >> 5);
652 if (key == K_HOME || key == K_KP_HOME)
655 con_backscroll = INT_MAX;
661 if (key == K_END || key == K_KP_END)
666 key_linepos = (int)strlen(key_line);
674 if (key_linepos < MAX_INPUTLINE-1)
677 len = (int)strlen(&key_line[key_linepos]);
678 // check insert mode, or always insert if at end of line
679 if (key_insert || len == 0)
681 // can't use strcpy to move string to right
683 memmove(&key_line[key_linepos + 1], &key_line[key_linepos], len);
685 key_line[key_linepos] = ascii;
690 //============================================================================
693 char chat_buffer[MAX_INPUTLINE];
694 unsigned int chat_bufferlen = 0;
696 extern int Nicks_CompleteChatLine(char *buffer, size_t size, unsigned int pos);
699 Key_Message (int key, int ascii)
702 if (key == K_ENTER || ascii == 10 || ascii == 13)
705 Cmd_ExecuteString(chat_buffer, src_command); // not Cbuf_AddText to allow semiclons in args; however, this allows no variables then. Use aliases!
707 Cmd_ForwardStringToServer(va("%s %s", chat_mode ? "say_team" : "say ", chat_buffer));
715 // TODO add support for arrow keys and simple editing
717 if (key == K_ESCAPE) {
724 if (key == K_BACKSPACE) {
725 if (chat_bufferlen) {
727 chat_buffer[chat_bufferlen] = 0;
733 chat_bufferlen = Nicks_CompleteChatLine(chat_buffer, sizeof(chat_buffer), chat_bufferlen);
737 if (chat_bufferlen == sizeof (chat_buffer) - 1)
741 return; // non printable
743 chat_buffer[chat_bufferlen++] = ascii;
744 chat_buffer[chat_bufferlen] = 0;
747 //============================================================================
752 Returns a key number to be used to index keybindings[] by looking at
753 the given string. Single ascii characters return themselves, while
754 the K_* names are matched up.
758 Key_StringToKeynum (const char *str)
765 return tolower(str[0]);
767 for (kn = keynames; kn->name; kn++) {
768 if (!strcasecmp (str, kn->name))
776 Returns a string (either a single ascii char, or a K_* name) for the
778 FIXME: handle quote special (general escape sequence?)
782 Key_KeynumToString (int keynum)
785 static char tinystr[2];
787 // -1 is an invalid code
789 return "<KEY NOT FOUND>";
791 // search overrides first, because some characters are special
792 for (kn = keynames; kn->name; kn++)
793 if (keynum == kn->keynum)
796 // if it is printable, output it as a single character
797 if (keynum > 32 && keynum < 256)
804 // if it is not overridden and not printable, we don't know what to do with it
805 return "<UNKNOWN KEYNUM>";
810 Key_SetBinding (int keynum, int bindmap, const char *binding)
815 if (keynum == -1 || keynum >= MAX_KEYS)
819 if (keybindings[bindmap][keynum]) {
820 Z_Free (keybindings[bindmap][keynum]);
821 keybindings[bindmap][keynum] = NULL;
823 if(!binding[0]) // make "" binds be removed --blub
825 // allocate memory for new binding
826 l = strlen (binding);
827 newbinding = (char *)Z_Malloc (l + 1);
828 memcpy (newbinding, binding, l + 1);
830 keybindings[bindmap][keynum] = newbinding;
834 Key_In_Unbind_f (void)
837 char *errchar = NULL;
839 if (Cmd_Argc () != 3) {
840 Con_Print("in_unbind <bindmap> <key> : remove commands from a key\n");
844 m = strtol(Cmd_Argv (1), &errchar, 0);
845 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
846 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
850 b = Key_StringToKeynum (Cmd_Argv (2));
852 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (2));
856 Key_SetBinding (b, m, "");
863 char cmd[MAX_INPUTLINE];
864 char *errchar = NULL;
868 if (c != 3 && c != 4) {
869 Con_Print("in_bind <bindmap> <key> [command] : attach a command to a key\n");
873 m = strtol(Cmd_Argv (1), &errchar, 0);
874 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
875 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
879 b = Key_StringToKeynum (Cmd_Argv (2));
880 if (b == -1 || b >= MAX_KEYS) {
881 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (2));
886 if (keybindings[m][b])
887 Con_Printf("\"%s\" = \"%s\"\n", Cmd_Argv (2), keybindings[m][b]);
889 Con_Printf("\"%s\" is not bound\n", Cmd_Argv (2));
892 // copy the rest of the command line
893 cmd[0] = 0; // start out with a null string
894 for (i = 3; i < c; i++) {
895 strlcat (cmd, Cmd_Argv (i), sizeof (cmd));
897 strlcat (cmd, " ", sizeof (cmd));
900 Key_SetBinding (b, m, cmd);
904 Key_In_Bindmap_f (void)
907 char *errchar = NULL;
912 Con_Print("in_bindmap <bindmap> <fallback>: set current bindmap and fallback\n");
916 m1 = strtol(Cmd_Argv (1), &errchar, 0);
917 if ((m1 < 0) || (m1 >= 8) || (errchar && *errchar)) {
918 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
922 m2 = strtol(Cmd_Argv (2), &errchar, 0);
923 if ((m2 < 0) || (m2 >= 8) || (errchar && *errchar)) {
924 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(2));
937 if (Cmd_Argc () != 2) {
938 Con_Print("unbind <key> : remove commands from a key\n");
942 b = Key_StringToKeynum (Cmd_Argv (1));
944 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (1));
948 Key_SetBinding (b, 0, "");
952 Key_Unbindall_f (void)
956 for (j = 0; j < 8; j++)
957 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
958 if (keybindings[j][i])
959 Key_SetBinding (i, j, "");
963 Key_PrintBindList(int j)
965 char bindbuf[MAX_INPUTLINE];
969 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
971 p = keybindings[j][i];
974 Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\");
976 Con_Printf("^2%s ^7= \"%s\"\n", Key_KeynumToString (i), bindbuf);
978 Con_Printf("^3bindmap %d: ^2%s ^7= \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
984 Key_In_BindList_f (void)
987 char *errchar = NULL;
991 m = strtol(Cmd_Argv(1), &errchar, 0);
992 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
993 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
996 Key_PrintBindList(m);
1000 for (m = 0; m < MAX_BINDMAPS; m++)
1001 Key_PrintBindList(m);
1006 Key_BindList_f (void)
1008 Key_PrintBindList(0);
1015 char cmd[MAX_INPUTLINE];
1019 if (c != 2 && c != 3) {
1020 Con_Print("bind <key> [command] : attach a command to a key\n");
1023 b = Key_StringToKeynum (Cmd_Argv (1));
1024 if (b == -1 || b >= MAX_KEYS) {
1025 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (1));
1030 if (keybindings[0][b])
1031 Con_Printf("\"%s\" = \"%s\"\n", Cmd_Argv (1), keybindings[0][b]);
1033 Con_Printf("\"%s\" is not bound\n", Cmd_Argv (1));
1036 // copy the rest of the command line
1037 cmd[0] = 0; // start out with a null string
1038 for (i = 2; i < c; i++) {
1039 strlcat (cmd, Cmd_Argv (i), sizeof (cmd));
1041 strlcat (cmd, " ", sizeof (cmd));
1044 Key_SetBinding (b, 0, cmd);
1049 Writes lines containing "bind key value"
1053 Key_WriteBindings (qfile_t *f)
1056 char bindbuf[MAX_INPUTLINE];
1059 for (j = 0; j < MAX_BINDMAPS; j++)
1061 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
1063 p = keybindings[j][i];
1066 Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\");
1068 FS_Printf(f, "bind %s \"%s\"\n", Key_KeynumToString (i), bindbuf);
1070 FS_Printf(f, "in_bind %d %s \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
1086 // register our functions
1088 Cmd_AddCommand ("in_bind", Key_In_Bind_f, "binds a command to the specified key in the selected bindmap");
1089 Cmd_AddCommand ("in_unbind", Key_In_Unbind_f, "removes command on the specified key in the selected bindmap");
1090 Cmd_AddCommand ("in_bindlist", Key_In_BindList_f, "bindlist: displays bound keys for all bindmaps, or the given bindmap");
1091 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");
1093 Cmd_AddCommand ("bind", Key_Bind_f, "binds a command to the specified key in bindmap 0");
1094 Cmd_AddCommand ("unbind", Key_Unbind_f, "removes a command on the specified key in bindmap 0");
1095 Cmd_AddCommand ("bindlist", Key_BindList_f, "bindlist: displays bound keys for bindmap 0 bindmaps");
1096 Cmd_AddCommand ("unbindall", Key_Unbindall_f, "removes all commands from all keys in all bindmaps (leaving only shift-escape and escape)");
1098 Cvar_RegisterVariable (&con_closeontoggleconsole);
1104 Key_History_Shutdown();
1107 const char *Key_GetBind (int key)
1110 if (key < 0 || key >= MAX_KEYS)
1112 bind = keybindings[key_bmap][key];
1114 bind = keybindings[key_bmap2][key];
1118 qboolean CL_VM_InputEvent (qboolean down, int key, int ascii);
1122 Called by the system between frames for both key up and key down events
1123 Should NOT be called during an interrupt!
1126 static char tbl_keyascii[MAX_KEYS];
1127 static keydest_t tbl_keydest[MAX_KEYS];
1130 Key_Event (int key, int ascii, qboolean down)
1134 keydest_t keydest = key_dest;
1136 if (key < 0 || key >= MAX_KEYS)
1140 bind = keybindings[key_bmap][key];
1142 bind = keybindings[key_bmap2][key];
1144 if (developer.integer >= 1000)
1145 Con_Printf("Key_Event(%i, '%c', %s) keydown %i bind \"%s\"\n", key, ascii, down ? "down" : "up", keydown[key], bind ? bind : "");
1147 if(key_consoleactive)
1148 keydest = key_console;
1152 // increment key repeat count each time a down is received so that things
1153 // which want to ignore key repeat can ignore it
1154 keydown[key] = min(keydown[key] + 1, 2);
1155 if(keydown[key] == 1) {
1156 tbl_keyascii[key] = ascii;
1157 tbl_keydest[key] = keydest;
1159 ascii = tbl_keyascii[key];
1160 keydest = tbl_keydest[key];
1165 // clear repeat count now that the key is released
1167 keydest = tbl_keydest[key];
1168 ascii = tbl_keyascii[key];
1171 if(keydest == key_void)
1174 // key_consoleactive is a flag not a key_dest because the console is a
1175 // high priority overlay ontop of the normal screen (designed as a safety
1176 // feature so that developers and users can rescue themselves from a bad
1179 // this also means that toggling the console on/off does not lose the old
1182 // specially handle escape (togglemenu) and shift-escape (toggleconsole)
1183 // engine bindings, these are not handled as normal binds so that the user
1184 // can recover from a completely empty bindmap
1185 if (key == K_ESCAPE)
1187 // ignore key repeats on escape
1188 if (keydown[key] > 1)
1191 // escape does these things:
1192 // key_consoleactive - close console
1193 // key_message - abort messagemode
1194 // key_menu - go to parent menu (or key_game)
1195 // key_game - open menu
1197 // in all modes shift-escape toggles console
1198 if (keydown[K_SHIFT])
1202 Con_ToggleConsole_f ();
1203 tbl_keydest[key] = key_void; // esc release should go nowhere (especially not to key_menu or key_game)
1213 if(key_consoleactive & KEY_CONSOLEACTIVE_FORCED)
1215 key_consoleactive &= ~KEY_CONSOLEACTIVE_USER;
1219 Con_ToggleConsole_f();
1225 Key_Message (key, ascii); // that'll close the message input
1229 case key_menu_grabbed:
1230 MR_KeyEvent (key, ascii, down);
1234 // csqc has priority over toggle menu if it wants to (e.g. handling escape for UI stuff in-game.. :sick:)
1235 q = CL_VM_InputEvent(down, key, ascii);
1241 Con_Printf ("Key_Event: Bad key_dest\n");
1246 // send function keydowns to interpreter no matter what mode is (unless the menu has specifically grabbed the keyboard, for rebinding keys)
1247 if (keydest != key_menu_grabbed)
1248 if (key >= K_F1 && key <= K_F12)
1252 if(keydown[key] == 1 && down)
1254 // button commands add keynum as a parm
1256 Cbuf_AddText (va("%s %i\n", bind, key));
1259 Cbuf_AddText (bind);
1260 Cbuf_AddText ("\n");
1262 } else if(bind[0] == '+' && !down && keydown[key] == 0)
1263 Cbuf_AddText(va("-%s %i\n", bind + 1, key));
1268 // send input to console if it wants it
1269 if (keydest == key_console)
1273 // con_closeontoggleconsole enables toggleconsole keys to close the
1274 // console, as long as they are not the color prefix character
1275 // (special exemption for german keyboard layouts)
1276 if (con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && (key_consoleactive & KEY_CONSOLEACTIVE_USER) && ascii != STRING_COLOR_TAG)
1278 Con_ToggleConsole_f ();
1281 Key_Console (key, ascii);
1285 // handle toggleconsole in menu too
1286 if (keydest == key_menu)
1288 if (down && con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && ascii != STRING_COLOR_TAG)
1290 Con_ToggleConsole_f ();
1291 tbl_keydest[key] = key_void; // key release should go nowhere (especially not to key_menu or key_game)
1296 // ignore binds while a video is played, let the video system handle the key event
1297 if (cl_videoplaying)
1299 CL_Video_KeyEvent (key, ascii, keydown[key] != 0);
1303 // anything else is a key press into the game, chat line, or menu
1308 Key_Message (key, ascii);
1311 case key_menu_grabbed:
1312 MR_KeyEvent (key, ascii, down);
1315 q = CL_VM_InputEvent(down, key, ascii);
1316 // ignore key repeats on binds and only send the bind if the event hasnt been already processed by csqc
1319 if(keydown[key] == 1 && down)
1321 // button commands add keynum as a parm
1323 Cbuf_AddText (va("%s %i\n", bind, key));
1326 Cbuf_AddText (bind);
1327 Cbuf_AddText ("\n");
1329 } else if(bind[0] == '+' && !down && keydown[key] == 0)
1330 Cbuf_AddText(va("-%s %i\n", bind + 1, key));
1334 Con_Printf ("Key_Event: Bad key_dest\n");
1344 Key_ClearStates (void)
1346 memset(keydown, 0, sizeof(keydown));