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 < CONBUFFER_LINES_COUNT(&history); ++i)
93 FS_Printf(historyfile, "%s\n", ConBuffer_GetLine(&history, i));
94 FS_Close(historyfile);
97 ConBuffer_Shutdown(&history);
100 static void Key_History_Push()
102 if(key_line[1]) // empty?
103 if(strcmp(key_line, "]quit")) // putting these into the history just sucks
104 if(strncmp(key_line, "]quit ", 6)) // putting these into the history just sucks
105 ConBuffer_AddLine(&history, key_line + 1, strlen(key_line) - 1, 0);
106 Con_Printf("%s\n", key_line); // don't mark empty lines as history
110 static void Key_History_Up()
112 if(history_line == -1) // editing the "new" line
113 strlcpy(history_savedline, key_line + 1, sizeof(history_savedline));
115 if(history_line == -1)
117 history_line = CONBUFFER_LINES_COUNT(&history) - 1;
118 if(history_line != -1)
120 strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
121 key_linepos = strlen(key_line);
124 else if(history_line > 0)
126 --history_line; // this also does -1 -> 0, so it is good
127 strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
128 key_linepos = strlen(key_line);
132 static void Key_History_Down()
134 if(history_line == -1) // editing the "new" line
137 if(history_line < CONBUFFER_LINES_COUNT(&history) - 1)
140 strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
145 strlcpy(key_line + 1, history_savedline, sizeof(key_line) - 1);
148 key_linepos = strlen(key_line);
151 static int key_bmap, key_bmap2;
152 static unsigned char keydown[MAX_KEYS]; // 0 = up, 1 = down, 2 = repeating
154 typedef struct keyname_s
161 static const keyname_t keynames[] = {
164 {"ESCAPE", K_ESCAPE},
167 // spacer so it lines up with keys.h
169 {"BACKSPACE", K_BACKSPACE},
170 {"UPARROW", K_UPARROW},
171 {"DOWNARROW", K_DOWNARROW},
172 {"LEFTARROW", K_LEFTARROW},
173 {"RIGHTARROW", K_RIGHTARROW},
201 {"NUMLOCK", K_NUMLOCK},
202 {"CAPSLOCK", K_CAPSLOCK},
203 {"SCROLLOCK", K_SCROLLOCK},
205 {"KP_INS", K_KP_INS },
207 {"KP_END", K_KP_END },
209 {"KP_DOWNARROW", K_KP_DOWNARROW },
211 {"KP_PGDN", K_KP_PGDN },
213 {"KP_LEFTARROW", K_KP_LEFTARROW },
216 {"KP_RIGHTARROW", K_KP_RIGHTARROW },
218 {"KP_HOME", K_KP_HOME },
220 {"KP_UPARROW", K_KP_UPARROW },
222 {"KP_PGUP", K_KP_PGUP },
224 {"KP_DEL", K_KP_DEL },
225 {"KP_PERIOD", K_KP_PERIOD},
226 {"KP_SLASH", K_KP_SLASH },
227 {"KP_DIVIDE", K_KP_DIVIDE},
228 {"KP_MULTIPLY", K_KP_MULTIPLY},
229 {"KP_MINUS", K_KP_MINUS},
230 {"KP_PLUS", K_KP_PLUS},
231 {"KP_ENTER", K_KP_ENTER},
232 {"KP_EQUALS", K_KP_EQUALS},
236 {"MOUSE1", K_MOUSE1},
238 {"MOUSE2", K_MOUSE2},
239 {"MOUSE3", K_MOUSE3},
240 {"MWHEELUP", K_MWHEELUP},
241 {"MWHEELDOWN", K_MWHEELDOWN},
242 {"MOUSE4", K_MOUSE4},
243 {"MOUSE5", K_MOUSE5},
244 {"MOUSE6", K_MOUSE6},
245 {"MOUSE7", K_MOUSE7},
246 {"MOUSE8", K_MOUSE8},
247 {"MOUSE9", K_MOUSE9},
248 {"MOUSE10", K_MOUSE10},
249 {"MOUSE11", K_MOUSE11},
250 {"MOUSE12", K_MOUSE12},
251 {"MOUSE13", K_MOUSE13},
252 {"MOUSE14", K_MOUSE14},
253 {"MOUSE15", K_MOUSE15},
254 {"MOUSE16", K_MOUSE16},
314 {"SEMICOLON", ';'}, // because a raw semicolon separates commands
318 {"APOSTROPHE", '\''},
319 {"BACKSLASH", '\\'}, // because a raw backslash is used for special characters
325 ==============================================================================
327 LINE TYPING INTO THE CONSOLE
329 ==============================================================================
333 Key_ClearEditLine (int edit_line)
335 memset (key_line, '\0', sizeof(key_line));
342 Interactive line editing and console scrollback
346 Key_Console (int key, int ascii)
348 // LordHavoc: copied most of this from Q2 to improve keyboard handling
375 case K_KP_RIGHTARROW:
395 if ((toupper(key) == 'V' && keydown[K_CTRL]) || ((key == K_INS || key == K_KP_INS) && keydown[K_SHIFT]))
398 if ((cbd = Sys_GetClipboardData()) != 0)
405 if (*p == '\n' || *p == '\r' || *p == '\b')
413 strtok(cbd, "\n\r\b");
415 i = (int)strlen(cbd);
416 if (i + key_linepos >= MAX_INPUTLINE)
417 i= MAX_INPUTLINE - key_linepos - 1;
420 // terencehill: insert the clipboard text between the characters of the line
421 char *temp = (char *) Z_Malloc(MAX_INPUTLINE);
424 if ( key_linepos < (int)strlen(key_line) )
425 strlcpy(temp, key_line + key_linepos, (int)strlen(key_line) - key_linepos +1);
426 key_line[key_linepos] = 0;
427 strlcat(key_line, cbd, sizeof(key_line));
429 strlcat(key_line, temp, sizeof(key_line));
442 Cbuf_AddText ("clear\n");
447 if (key == K_ENTER || key == K_KP_ENTER)
449 Cbuf_AddText (key_line+1); // skip the ]
453 key_line[1] = 0; // EvilTypeGuy: null terminate
455 // force an update, because the command may take some time
456 if (cls.state == ca_disconnected)
463 // Enhanced command completion
464 // by EvilTypeGuy eviltypeguy@qeradiant.com
465 // Thanks to Fett, Taniwha
466 Con_CompleteCommandLine();
470 // Advanced Console Editing by Radix radix@planetquake.com
471 // Added/Modified by EvilTypeGuy eviltypeguy@qeradiant.com
473 // Enhanced by terencehill
475 // move cursor to the previous character
476 if (key == K_LEFTARROW || key == K_KP_LEFTARROW)
480 if(keydown[K_CTRL]) // move cursor to the previous word
489 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
492 key_linepos = pos + 1;
494 else if(keydown[K_SHIFT]) // move cursor to the previous character ignoring colors
499 if(pos-1 > 0 && key_line[pos-1] == STRING_COLOR_TAG && isdigit(key_line[pos]))
501 else if(pos-4 > 0 && key_line[pos-4] == STRING_COLOR_TAG && key_line[pos-3] == STRING_COLOR_RGB_TAG_CHAR
502 && isxdigit(key_line[pos-2]) && isxdigit(key_line[pos-1]) && isxdigit(key_line[pos]))
509 key_linepos = pos + 1;
516 // delete char before cursor
517 if (key == K_BACKSPACE || (key == 'h' && keydown[K_CTRL]))
521 strlcpy(key_line + key_linepos - 1, key_line + key_linepos, sizeof(key_line) + 1 - key_linepos);
527 // delete char on cursor
528 if (key == K_DEL || key == K_KP_DEL)
531 linelen = strlen(key_line);
532 if (key_linepos < (int)linelen)
533 memmove(key_line + key_linepos, key_line + key_linepos + 1, linelen - key_linepos);
538 // move cursor to the next character
539 if (key == K_RIGHTARROW || key == K_KP_RIGHTARROW)
541 if (key_linepos >= (int)strlen(key_line))
543 if(keydown[K_CTRL]) // move cursor to the next word
547 len = (int)strlen(key_line);
552 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
557 else if(keydown[K_SHIFT]) // move cursor to the next character ignoring colors
560 len = (int)strlen(key_line);
562 // check if there is a color tag right after the cursor
563 if (key_line[pos] == STRING_COLOR_TAG)
565 if(isdigit(key_line[pos+1]))
567 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]))
572 // now go beyond all next consecutive color tags, if any
574 while (key_line[pos] == STRING_COLOR_TAG)
576 if(isdigit(key_line[pos+1]))
578 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]))
590 if (key == K_INS || key == K_KP_INS) // toggle insert mode
596 // End Advanced Console Editing
598 if (key == K_UPARROW || key == K_KP_UPARROW || (key == 'p' && keydown[K_CTRL]))
604 if (key == K_DOWNARROW || key == K_KP_DOWNARROW || (key == 'n' && keydown[K_CTRL]))
610 if (key == K_PGUP || key == K_KP_PGUP || key == K_MWHEELUP)
617 con_backscroll += ((int) vid_conheight.integer >> 5);
621 if (key == K_PGDN || key == K_KP_PGDN || key == K_MWHEELDOWN)
628 con_backscroll -= ((int) vid_conheight.integer >> 5);
632 if (key == K_HOME || key == K_KP_HOME)
635 con_backscroll = INT_MAX;
641 if (key == K_END || key == K_KP_END)
646 key_linepos = (int)strlen(key_line);
654 if (key_linepos < MAX_INPUTLINE-1)
657 len = (int)strlen(&key_line[key_linepos]);
658 // check insert mode, or always insert if at end of line
659 if (key_insert || len == 0)
661 // can't use strcpy to move string to right
663 memmove(&key_line[key_linepos + 1], &key_line[key_linepos], len);
665 key_line[key_linepos] = ascii;
670 //============================================================================
673 char chat_buffer[MAX_INPUTLINE];
674 unsigned int chat_bufferlen = 0;
676 extern int Nicks_CompleteChatLine(char *buffer, size_t size, unsigned int pos);
679 Key_Message (int key, int ascii)
682 if (key == K_ENTER || ascii == 10 || ascii == 13)
685 Cmd_ExecuteString(chat_buffer, src_command); // not Cbuf_AddText to allow semiclons in args; however, this allows no variables then. Use aliases!
687 Cmd_ForwardStringToServer(va("%s %s", chat_mode ? "say_team" : "say ", chat_buffer));
695 // TODO add support for arrow keys and simple editing
697 if (key == K_ESCAPE) {
704 if (key == K_BACKSPACE) {
705 if (chat_bufferlen) {
707 chat_buffer[chat_bufferlen] = 0;
713 chat_bufferlen = Nicks_CompleteChatLine(chat_buffer, sizeof(chat_buffer), chat_bufferlen);
717 if (chat_bufferlen == sizeof (chat_buffer) - 1)
721 return; // non printable
723 chat_buffer[chat_bufferlen++] = ascii;
724 chat_buffer[chat_bufferlen] = 0;
727 //============================================================================
732 Returns a key number to be used to index keybindings[] by looking at
733 the given string. Single ascii characters return themselves, while
734 the K_* names are matched up.
738 Key_StringToKeynum (const char *str)
745 return tolower(str[0]);
747 for (kn = keynames; kn->name; kn++) {
748 if (!strcasecmp (str, kn->name))
756 Returns a string (either a single ascii char, or a K_* name) for the
758 FIXME: handle quote special (general escape sequence?)
762 Key_KeynumToString (int keynum)
765 static char tinystr[2];
767 // -1 is an invalid code
769 return "<KEY NOT FOUND>";
771 // search overrides first, because some characters are special
772 for (kn = keynames; kn->name; kn++)
773 if (keynum == kn->keynum)
776 // if it is printable, output it as a single character
777 if (keynum > 32 && keynum < 256)
784 // if it is not overridden and not printable, we don't know what to do with it
785 return "<UNKNOWN KEYNUM>";
790 Key_SetBinding (int keynum, int bindmap, const char *binding)
795 if (keynum == -1 || keynum >= MAX_KEYS)
799 if (keybindings[bindmap][keynum]) {
800 Z_Free (keybindings[bindmap][keynum]);
801 keybindings[bindmap][keynum] = NULL;
803 if(!binding[0]) // make "" binds be removed --blub
805 // allocate memory for new binding
806 l = strlen (binding);
807 newbinding = (char *)Z_Malloc (l + 1);
808 memcpy (newbinding, binding, l + 1);
810 keybindings[bindmap][keynum] = newbinding;
814 Key_In_Unbind_f (void)
817 char *errchar = NULL;
819 if (Cmd_Argc () != 3) {
820 Con_Print("in_unbind <bindmap> <key> : remove commands from a key\n");
824 m = strtol(Cmd_Argv (1), &errchar, 0);
825 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
826 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
830 b = Key_StringToKeynum (Cmd_Argv (2));
832 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (2));
836 Key_SetBinding (b, m, "");
843 char cmd[MAX_INPUTLINE];
844 char *errchar = NULL;
848 if (c != 3 && c != 4) {
849 Con_Print("in_bind <bindmap> <key> [command] : attach a command to a key\n");
853 m = strtol(Cmd_Argv (1), &errchar, 0);
854 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
855 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
859 b = Key_StringToKeynum (Cmd_Argv (2));
860 if (b == -1 || b >= MAX_KEYS) {
861 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (2));
866 if (keybindings[m][b])
867 Con_Printf("\"%s\" = \"%s\"\n", Cmd_Argv (2), keybindings[m][b]);
869 Con_Printf("\"%s\" is not bound\n", Cmd_Argv (2));
872 // copy the rest of the command line
873 cmd[0] = 0; // start out with a null string
874 for (i = 3; i < c; i++) {
875 strlcat (cmd, Cmd_Argv (i), sizeof (cmd));
877 strlcat (cmd, " ", sizeof (cmd));
880 Key_SetBinding (b, m, cmd);
884 Key_In_Bindmap_f (void)
887 char *errchar = NULL;
892 Con_Print("in_bindmap <bindmap> <fallback>: set current bindmap and fallback\n");
896 m1 = strtol(Cmd_Argv (1), &errchar, 0);
897 if ((m1 < 0) || (m1 >= 8) || (errchar && *errchar)) {
898 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
902 m2 = strtol(Cmd_Argv (2), &errchar, 0);
903 if ((m2 < 0) || (m2 >= 8) || (errchar && *errchar)) {
904 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(2));
917 if (Cmd_Argc () != 2) {
918 Con_Print("unbind <key> : remove commands from a key\n");
922 b = Key_StringToKeynum (Cmd_Argv (1));
924 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (1));
928 Key_SetBinding (b, 0, "");
932 Key_Unbindall_f (void)
936 for (j = 0; j < 8; j++)
937 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
938 if (keybindings[j][i])
939 Key_SetBinding (i, j, "");
943 Key_PrintBindList(int j)
945 char bindbuf[MAX_INPUTLINE];
949 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
951 p = keybindings[j][i];
954 Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\");
956 Con_Printf("^2%s ^7= \"%s\"\n", Key_KeynumToString (i), bindbuf);
958 Con_Printf("^3bindmap %d: ^2%s ^7= \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
964 Key_In_BindList_f (void)
967 char *errchar = NULL;
971 m = strtol(Cmd_Argv(1), &errchar, 0);
972 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
973 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
976 Key_PrintBindList(m);
980 for (m = 0; m < MAX_BINDMAPS; m++)
981 Key_PrintBindList(m);
986 Key_BindList_f (void)
988 Key_PrintBindList(0);
995 char cmd[MAX_INPUTLINE];
999 if (c != 2 && c != 3) {
1000 Con_Print("bind <key> [command] : attach a command to a key\n");
1003 b = Key_StringToKeynum (Cmd_Argv (1));
1004 if (b == -1 || b >= MAX_KEYS) {
1005 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (1));
1010 if (keybindings[0][b])
1011 Con_Printf("\"%s\" = \"%s\"\n", Cmd_Argv (1), keybindings[0][b]);
1013 Con_Printf("\"%s\" is not bound\n", Cmd_Argv (1));
1016 // copy the rest of the command line
1017 cmd[0] = 0; // start out with a null string
1018 for (i = 2; i < c; i++) {
1019 strlcat (cmd, Cmd_Argv (i), sizeof (cmd));
1021 strlcat (cmd, " ", sizeof (cmd));
1024 Key_SetBinding (b, 0, cmd);
1029 Writes lines containing "bind key value"
1033 Key_WriteBindings (qfile_t *f)
1036 char bindbuf[MAX_INPUTLINE];
1039 for (j = 0; j < MAX_BINDMAPS; j++)
1041 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
1043 p = keybindings[j][i];
1046 Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\");
1048 FS_Printf(f, "bind %s \"%s\"\n", Key_KeynumToString (i), bindbuf);
1050 FS_Printf(f, "in_bind %d %s \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
1066 // register our functions
1068 Cmd_AddCommand ("in_bind", Key_In_Bind_f, "binds a command to the specified key in the selected bindmap");
1069 Cmd_AddCommand ("in_unbind", Key_In_Unbind_f, "removes command on the specified key in the selected bindmap");
1070 Cmd_AddCommand ("in_bindlist", Key_In_BindList_f, "bindlist: displays bound keys for all bindmaps, or the given bindmap");
1071 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");
1073 Cmd_AddCommand ("bind", Key_Bind_f, "binds a command to the specified key in bindmap 0");
1074 Cmd_AddCommand ("unbind", Key_Unbind_f, "removes a command on the specified key in bindmap 0");
1075 Cmd_AddCommand ("bindlist", Key_BindList_f, "bindlist: displays bound keys for bindmap 0 bindmaps");
1076 Cmd_AddCommand ("unbindall", Key_Unbindall_f, "removes all commands from all keys in all bindmaps (leaving only shift-escape and escape)");
1078 Cvar_RegisterVariable (&con_closeontoggleconsole);
1084 Key_History_Shutdown();
1087 const char *Key_GetBind (int key)
1090 if (key < 0 || key >= MAX_KEYS)
1092 bind = keybindings[key_bmap][key];
1094 bind = keybindings[key_bmap2][key];
1098 qboolean CL_VM_InputEvent (qboolean down, int key, int ascii);
1102 Called by the system between frames for both key up and key down events
1103 Should NOT be called during an interrupt!
1106 static char tbl_keyascii[MAX_KEYS];
1107 static keydest_t tbl_keydest[MAX_KEYS];
1110 Key_Event (int key, int ascii, qboolean down)
1114 keydest_t keydest = key_dest;
1116 if (key < 0 || key >= MAX_KEYS)
1120 bind = keybindings[key_bmap][key];
1122 bind = keybindings[key_bmap2][key];
1124 if (developer.integer >= 1000)
1125 Con_Printf("Key_Event(%i, '%c', %s) keydown %i bind \"%s\"\n", key, ascii, down ? "down" : "up", keydown[key], bind ? bind : "");
1127 if(key_consoleactive)
1128 keydest = key_console;
1132 // increment key repeat count each time a down is received so that things
1133 // which want to ignore key repeat can ignore it
1134 keydown[key] = min(keydown[key] + 1, 2);
1135 if(keydown[key] == 1) {
1136 tbl_keyascii[key] = ascii;
1137 tbl_keydest[key] = keydest;
1139 ascii = tbl_keyascii[key];
1140 keydest = tbl_keydest[key];
1145 // clear repeat count now that the key is released
1147 keydest = tbl_keydest[key];
1148 ascii = tbl_keyascii[key];
1151 if(keydest == key_void)
1154 // key_consoleactive is a flag not a key_dest because the console is a
1155 // high priority overlay ontop of the normal screen (designed as a safety
1156 // feature so that developers and users can rescue themselves from a bad
1159 // this also means that toggling the console on/off does not lose the old
1162 // specially handle escape (togglemenu) and shift-escape (toggleconsole)
1163 // engine bindings, these are not handled as normal binds so that the user
1164 // can recover from a completely empty bindmap
1165 if (key == K_ESCAPE)
1167 // ignore key repeats on escape
1168 if (keydown[key] > 1)
1171 // escape does these things:
1172 // key_consoleactive - close console
1173 // key_message - abort messagemode
1174 // key_menu - go to parent menu (or key_game)
1175 // key_game - open menu
1177 // in all modes shift-escape toggles console
1178 if (keydown[K_SHIFT])
1182 Con_ToggleConsole_f ();
1183 tbl_keydest[key] = key_void; // esc release should go nowhere (especially not to key_menu or key_game)
1193 if(key_consoleactive & KEY_CONSOLEACTIVE_FORCED)
1195 key_consoleactive &= ~KEY_CONSOLEACTIVE_USER;
1199 Con_ToggleConsole_f();
1205 Key_Message (key, ascii); // that'll close the message input
1209 case key_menu_grabbed:
1210 MR_KeyEvent (key, ascii, down);
1214 // csqc has priority over toggle menu if it wants to (e.g. handling escape for UI stuff in-game.. :sick:)
1215 q = CL_VM_InputEvent(down, key, ascii);
1221 Con_Printf ("Key_Event: Bad key_dest\n");
1226 // send function keydowns to interpreter no matter what mode is (unless the menu has specifically grabbed the keyboard, for rebinding keys)
1227 if (keydest != key_menu_grabbed)
1228 if (key >= K_F1 && key <= K_F12)
1232 if(keydown[key] == 1 && down)
1234 // button commands add keynum as a parm
1236 Cbuf_AddText (va("%s %i\n", bind, key));
1239 Cbuf_AddText (bind);
1240 Cbuf_AddText ("\n");
1242 } else if(bind[0] == '+' && !down && keydown[key] == 0)
1243 Cbuf_AddText(va("-%s %i\n", bind + 1, key));
1248 // send input to console if it wants it
1249 if (keydest == key_console)
1253 // con_closeontoggleconsole enables toggleconsole keys to close the
1254 // console, as long as they are not the color prefix character
1255 // (special exemption for german keyboard layouts)
1256 if (con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && (key_consoleactive & KEY_CONSOLEACTIVE_USER) && ascii != STRING_COLOR_TAG)
1258 Con_ToggleConsole_f ();
1261 Key_Console (key, ascii);
1265 // handle toggleconsole in menu too
1266 if (keydest == key_menu)
1268 if (down && con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && ascii != STRING_COLOR_TAG)
1270 Con_ToggleConsole_f ();
1271 tbl_keydest[key] = key_void; // key release should go nowhere (especially not to key_menu or key_game)
1276 // ignore binds while a video is played, let the video system handle the key event
1277 if (cl_videoplaying)
1279 CL_Video_KeyEvent (key, ascii, keydown[key] != 0);
1283 // anything else is a key press into the game, chat line, or menu
1288 Key_Message (key, ascii);
1291 case key_menu_grabbed:
1292 MR_KeyEvent (key, ascii, down);
1295 q = CL_VM_InputEvent(down, key, ascii);
1296 // ignore key repeats on binds and only send the bind if the event hasnt been already processed by csqc
1299 if(keydown[key] == 1 && down)
1301 // button commands add keynum as a parm
1303 Cbuf_AddText (va("%s %i\n", bind, key));
1306 Cbuf_AddText (bind);
1307 Cbuf_AddText ("\n");
1309 } else if(bind[0] == '+' && !down && keydown[key] == 0)
1310 Cbuf_AddText(va("-%s %i\n", bind + 1, key));
1314 Con_Printf ("Key_Event: Bad key_dest\n");
1324 Key_ClearStates (void)
1326 memset(keydown, 0, sizeof(keydown));