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 (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));
438 if (key == 'l' && keydown[K_CTRL])
440 Cbuf_AddText ("clear\n");
444 if (key == 'u' && keydown[K_CTRL]) // like vi/readline ^u: delete currently edited line
453 if (key == 'q' && keydown[K_CTRL]) // like zsh ^q: push line to history, don't execute, and clear
463 if (key == K_ENTER || key == K_KP_ENTER)
465 Cbuf_AddText (key_line+1); // skip the ]
469 key_line[1] = 0; // EvilTypeGuy: null terminate
471 // force an update, because the command may take some time
472 if (cls.state == ca_disconnected)
479 // Enhanced command completion
480 // by EvilTypeGuy eviltypeguy@qeradiant.com
481 // Thanks to Fett, Taniwha
482 Con_CompleteCommandLine();
486 // Advanced Console Editing by Radix radix@planetquake.com
487 // Added/Modified by EvilTypeGuy eviltypeguy@qeradiant.com
489 // Enhanced by terencehill
491 // move cursor to the previous character
492 if (key == K_LEFTARROW || key == K_KP_LEFTARROW)
496 if(keydown[K_CTRL]) // move cursor to the previous word
505 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
508 key_linepos = pos + 1;
510 else if(keydown[K_SHIFT]) // move cursor to the previous character ignoring colors
515 if(pos-1 > 0 && key_line[pos-1] == STRING_COLOR_TAG && isdigit(key_line[pos]))
517 else if(pos-4 > 0 && key_line[pos-4] == STRING_COLOR_TAG && key_line[pos-3] == STRING_COLOR_RGB_TAG_CHAR
518 && isxdigit(key_line[pos-2]) && isxdigit(key_line[pos-1]) && isxdigit(key_line[pos]))
525 key_linepos = pos + 1;
532 // delete char before cursor
533 if (key == K_BACKSPACE || (key == 'h' && keydown[K_CTRL]))
537 strlcpy(key_line + key_linepos - 1, key_line + key_linepos, sizeof(key_line) + 1 - key_linepos);
543 // delete char on cursor
544 if (key == K_DEL || key == K_KP_DEL)
547 linelen = strlen(key_line);
548 if (key_linepos < (int)linelen)
549 memmove(key_line + key_linepos, key_line + key_linepos + 1, linelen - key_linepos);
554 // move cursor to the next character
555 if (key == K_RIGHTARROW || key == K_KP_RIGHTARROW)
557 if (key_linepos >= (int)strlen(key_line))
559 if(keydown[K_CTRL]) // move cursor to the next word
563 len = (int)strlen(key_line);
568 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
573 else if(keydown[K_SHIFT]) // move cursor to the next character ignoring colors
576 len = (int)strlen(key_line);
578 // check if there is a color tag right after the cursor
579 if (key_line[pos] == STRING_COLOR_TAG)
581 if(isdigit(key_line[pos+1]))
583 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 // now go beyond all next consecutive color tags, if any
590 while (key_line[pos] == STRING_COLOR_TAG)
592 if(isdigit(key_line[pos+1]))
594 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]))
606 if (key == K_INS || key == K_KP_INS) // toggle insert mode
612 // End Advanced Console Editing
614 if (key == K_UPARROW || key == K_KP_UPARROW || (key == 'p' && keydown[K_CTRL]))
620 if (key == K_DOWNARROW || key == K_KP_DOWNARROW || (key == 'n' && keydown[K_CTRL]))
626 if (key == K_PGUP || key == K_KP_PGUP || key == K_MWHEELUP)
633 con_backscroll += ((int) vid_conheight.integer >> 5);
637 if (key == K_PGDN || key == K_KP_PGDN || key == K_MWHEELDOWN)
644 con_backscroll -= ((int) vid_conheight.integer >> 5);
648 if (key == K_HOME || key == K_KP_HOME)
651 con_backscroll = INT_MAX;
657 if (key == K_END || key == K_KP_END)
662 key_linepos = (int)strlen(key_line);
670 if (key_linepos < MAX_INPUTLINE-1)
673 len = (int)strlen(&key_line[key_linepos]);
674 // check insert mode, or always insert if at end of line
675 if (key_insert || len == 0)
677 // can't use strcpy to move string to right
679 memmove(&key_line[key_linepos + 1], &key_line[key_linepos], len);
681 key_line[key_linepos] = ascii;
686 //============================================================================
689 char chat_buffer[MAX_INPUTLINE];
690 unsigned int chat_bufferlen = 0;
692 extern int Nicks_CompleteChatLine(char *buffer, size_t size, unsigned int pos);
695 Key_Message (int key, int ascii)
698 if (key == K_ENTER || ascii == 10 || ascii == 13)
701 Cmd_ExecuteString(chat_buffer, src_command); // not Cbuf_AddText to allow semiclons in args; however, this allows no variables then. Use aliases!
703 Cmd_ForwardStringToServer(va("%s %s", chat_mode ? "say_team" : "say ", chat_buffer));
711 // TODO add support for arrow keys and simple editing
713 if (key == K_ESCAPE) {
720 if (key == K_BACKSPACE) {
721 if (chat_bufferlen) {
723 chat_buffer[chat_bufferlen] = 0;
729 chat_bufferlen = Nicks_CompleteChatLine(chat_buffer, sizeof(chat_buffer), chat_bufferlen);
733 if (chat_bufferlen == sizeof (chat_buffer) - 1)
737 return; // non printable
739 chat_buffer[chat_bufferlen++] = ascii;
740 chat_buffer[chat_bufferlen] = 0;
743 //============================================================================
748 Returns a key number to be used to index keybindings[] by looking at
749 the given string. Single ascii characters return themselves, while
750 the K_* names are matched up.
754 Key_StringToKeynum (const char *str)
761 return tolower(str[0]);
763 for (kn = keynames; kn->name; kn++) {
764 if (!strcasecmp (str, kn->name))
772 Returns a string (either a single ascii char, or a K_* name) for the
774 FIXME: handle quote special (general escape sequence?)
778 Key_KeynumToString (int keynum)
781 static char tinystr[2];
783 // -1 is an invalid code
785 return "<KEY NOT FOUND>";
787 // search overrides first, because some characters are special
788 for (kn = keynames; kn->name; kn++)
789 if (keynum == kn->keynum)
792 // if it is printable, output it as a single character
793 if (keynum > 32 && keynum < 256)
800 // if it is not overridden and not printable, we don't know what to do with it
801 return "<UNKNOWN KEYNUM>";
806 Key_SetBinding (int keynum, int bindmap, const char *binding)
811 if (keynum == -1 || keynum >= MAX_KEYS)
815 if (keybindings[bindmap][keynum]) {
816 Z_Free (keybindings[bindmap][keynum]);
817 keybindings[bindmap][keynum] = NULL;
819 if(!binding[0]) // make "" binds be removed --blub
821 // allocate memory for new binding
822 l = strlen (binding);
823 newbinding = (char *)Z_Malloc (l + 1);
824 memcpy (newbinding, binding, l + 1);
826 keybindings[bindmap][keynum] = newbinding;
830 Key_In_Unbind_f (void)
833 char *errchar = NULL;
835 if (Cmd_Argc () != 3) {
836 Con_Print("in_unbind <bindmap> <key> : remove commands from a key\n");
840 m = strtol(Cmd_Argv (1), &errchar, 0);
841 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
842 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
846 b = Key_StringToKeynum (Cmd_Argv (2));
848 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (2));
852 Key_SetBinding (b, m, "");
859 char cmd[MAX_INPUTLINE];
860 char *errchar = NULL;
864 if (c != 3 && c != 4) {
865 Con_Print("in_bind <bindmap> <key> [command] : attach a command to a key\n");
869 m = strtol(Cmd_Argv (1), &errchar, 0);
870 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
871 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
875 b = Key_StringToKeynum (Cmd_Argv (2));
876 if (b == -1 || b >= MAX_KEYS) {
877 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (2));
882 if (keybindings[m][b])
883 Con_Printf("\"%s\" = \"%s\"\n", Cmd_Argv (2), keybindings[m][b]);
885 Con_Printf("\"%s\" is not bound\n", Cmd_Argv (2));
888 // copy the rest of the command line
889 cmd[0] = 0; // start out with a null string
890 for (i = 3; i < c; i++) {
891 strlcat (cmd, Cmd_Argv (i), sizeof (cmd));
893 strlcat (cmd, " ", sizeof (cmd));
896 Key_SetBinding (b, m, cmd);
900 Key_In_Bindmap_f (void)
903 char *errchar = NULL;
908 Con_Print("in_bindmap <bindmap> <fallback>: set current bindmap and fallback\n");
912 m1 = strtol(Cmd_Argv (1), &errchar, 0);
913 if ((m1 < 0) || (m1 >= 8) || (errchar && *errchar)) {
914 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
918 m2 = strtol(Cmd_Argv (2), &errchar, 0);
919 if ((m2 < 0) || (m2 >= 8) || (errchar && *errchar)) {
920 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(2));
933 if (Cmd_Argc () != 2) {
934 Con_Print("unbind <key> : remove commands from a key\n");
938 b = Key_StringToKeynum (Cmd_Argv (1));
940 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (1));
944 Key_SetBinding (b, 0, "");
948 Key_Unbindall_f (void)
952 for (j = 0; j < 8; j++)
953 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
954 if (keybindings[j][i])
955 Key_SetBinding (i, j, "");
959 Key_PrintBindList(int j)
961 char bindbuf[MAX_INPUTLINE];
965 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
967 p = keybindings[j][i];
970 Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\");
972 Con_Printf("^2%s ^7= \"%s\"\n", Key_KeynumToString (i), bindbuf);
974 Con_Printf("^3bindmap %d: ^2%s ^7= \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
980 Key_In_BindList_f (void)
983 char *errchar = NULL;
987 m = strtol(Cmd_Argv(1), &errchar, 0);
988 if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
989 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
992 Key_PrintBindList(m);
996 for (m = 0; m < MAX_BINDMAPS; m++)
997 Key_PrintBindList(m);
1002 Key_BindList_f (void)
1004 Key_PrintBindList(0);
1011 char cmd[MAX_INPUTLINE];
1015 if (c != 2 && c != 3) {
1016 Con_Print("bind <key> [command] : attach a command to a key\n");
1019 b = Key_StringToKeynum (Cmd_Argv (1));
1020 if (b == -1 || b >= MAX_KEYS) {
1021 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (1));
1026 if (keybindings[0][b])
1027 Con_Printf("\"%s\" = \"%s\"\n", Cmd_Argv (1), keybindings[0][b]);
1029 Con_Printf("\"%s\" is not bound\n", Cmd_Argv (1));
1032 // copy the rest of the command line
1033 cmd[0] = 0; // start out with a null string
1034 for (i = 2; i < c; i++) {
1035 strlcat (cmd, Cmd_Argv (i), sizeof (cmd));
1037 strlcat (cmd, " ", sizeof (cmd));
1040 Key_SetBinding (b, 0, cmd);
1045 Writes lines containing "bind key value"
1049 Key_WriteBindings (qfile_t *f)
1052 char bindbuf[MAX_INPUTLINE];
1055 for (j = 0; j < MAX_BINDMAPS; j++)
1057 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
1059 p = keybindings[j][i];
1062 Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\");
1064 FS_Printf(f, "bind %s \"%s\"\n", Key_KeynumToString (i), bindbuf);
1066 FS_Printf(f, "in_bind %d %s \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
1082 // register our functions
1084 Cmd_AddCommand ("in_bind", Key_In_Bind_f, "binds a command to the specified key in the selected bindmap");
1085 Cmd_AddCommand ("in_unbind", Key_In_Unbind_f, "removes command on the specified key in the selected bindmap");
1086 Cmd_AddCommand ("in_bindlist", Key_In_BindList_f, "bindlist: displays bound keys for all bindmaps, or the given bindmap");
1087 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");
1089 Cmd_AddCommand ("bind", Key_Bind_f, "binds a command to the specified key in bindmap 0");
1090 Cmd_AddCommand ("unbind", Key_Unbind_f, "removes a command on the specified key in bindmap 0");
1091 Cmd_AddCommand ("bindlist", Key_BindList_f, "bindlist: displays bound keys for bindmap 0 bindmaps");
1092 Cmd_AddCommand ("unbindall", Key_Unbindall_f, "removes all commands from all keys in all bindmaps (leaving only shift-escape and escape)");
1094 Cvar_RegisterVariable (&con_closeontoggleconsole);
1100 Key_History_Shutdown();
1103 const char *Key_GetBind (int key)
1106 if (key < 0 || key >= MAX_KEYS)
1108 bind = keybindings[key_bmap][key];
1110 bind = keybindings[key_bmap2][key];
1114 qboolean CL_VM_InputEvent (qboolean down, int key, int ascii);
1118 Called by the system between frames for both key up and key down events
1119 Should NOT be called during an interrupt!
1122 static char tbl_keyascii[MAX_KEYS];
1123 static keydest_t tbl_keydest[MAX_KEYS];
1126 Key_Event (int key, int ascii, qboolean down)
1130 keydest_t keydest = key_dest;
1132 if (key < 0 || key >= MAX_KEYS)
1136 bind = keybindings[key_bmap][key];
1138 bind = keybindings[key_bmap2][key];
1140 if (developer.integer >= 1000)
1141 Con_Printf("Key_Event(%i, '%c', %s) keydown %i bind \"%s\"\n", key, ascii, down ? "down" : "up", keydown[key], bind ? bind : "");
1143 if(key_consoleactive)
1144 keydest = key_console;
1148 // increment key repeat count each time a down is received so that things
1149 // which want to ignore key repeat can ignore it
1150 keydown[key] = min(keydown[key] + 1, 2);
1151 if(keydown[key] == 1) {
1152 tbl_keyascii[key] = ascii;
1153 tbl_keydest[key] = keydest;
1155 ascii = tbl_keyascii[key];
1156 keydest = tbl_keydest[key];
1161 // clear repeat count now that the key is released
1163 keydest = tbl_keydest[key];
1164 ascii = tbl_keyascii[key];
1167 if(keydest == key_void)
1170 // key_consoleactive is a flag not a key_dest because the console is a
1171 // high priority overlay ontop of the normal screen (designed as a safety
1172 // feature so that developers and users can rescue themselves from a bad
1175 // this also means that toggling the console on/off does not lose the old
1178 // specially handle escape (togglemenu) and shift-escape (toggleconsole)
1179 // engine bindings, these are not handled as normal binds so that the user
1180 // can recover from a completely empty bindmap
1181 if (key == K_ESCAPE)
1183 // ignore key repeats on escape
1184 if (keydown[key] > 1)
1187 // escape does these things:
1188 // key_consoleactive - close console
1189 // key_message - abort messagemode
1190 // key_menu - go to parent menu (or key_game)
1191 // key_game - open menu
1193 // in all modes shift-escape toggles console
1194 if (keydown[K_SHIFT])
1198 Con_ToggleConsole_f ();
1199 tbl_keydest[key] = key_void; // esc release should go nowhere (especially not to key_menu or key_game)
1209 if(key_consoleactive & KEY_CONSOLEACTIVE_FORCED)
1211 key_consoleactive &= ~KEY_CONSOLEACTIVE_USER;
1215 Con_ToggleConsole_f();
1221 Key_Message (key, ascii); // that'll close the message input
1225 case key_menu_grabbed:
1226 MR_KeyEvent (key, ascii, down);
1230 // csqc has priority over toggle menu if it wants to (e.g. handling escape for UI stuff in-game.. :sick:)
1231 q = CL_VM_InputEvent(down, key, ascii);
1237 Con_Printf ("Key_Event: Bad key_dest\n");
1242 // send function keydowns to interpreter no matter what mode is (unless the menu has specifically grabbed the keyboard, for rebinding keys)
1243 if (keydest != key_menu_grabbed)
1244 if (key >= K_F1 && key <= K_F12)
1248 if(keydown[key] == 1 && down)
1250 // button commands add keynum as a parm
1252 Cbuf_AddText (va("%s %i\n", bind, key));
1255 Cbuf_AddText (bind);
1256 Cbuf_AddText ("\n");
1258 } else if(bind[0] == '+' && !down && keydown[key] == 0)
1259 Cbuf_AddText(va("-%s %i\n", bind + 1, key));
1264 // send input to console if it wants it
1265 if (keydest == key_console)
1269 // con_closeontoggleconsole enables toggleconsole keys to close the
1270 // console, as long as they are not the color prefix character
1271 // (special exemption for german keyboard layouts)
1272 if (con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && (key_consoleactive & KEY_CONSOLEACTIVE_USER) && ascii != STRING_COLOR_TAG)
1274 Con_ToggleConsole_f ();
1277 Key_Console (key, ascii);
1281 // handle toggleconsole in menu too
1282 if (keydest == key_menu)
1284 if (down && con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && ascii != STRING_COLOR_TAG)
1286 Con_ToggleConsole_f ();
1287 tbl_keydest[key] = key_void; // key release should go nowhere (especially not to key_menu or key_game)
1292 // ignore binds while a video is played, let the video system handle the key event
1293 if (cl_videoplaying)
1295 CL_Video_KeyEvent (key, ascii, keydown[key] != 0);
1299 // anything else is a key press into the game, chat line, or menu
1304 Key_Message (key, ascii);
1307 case key_menu_grabbed:
1308 MR_KeyEvent (key, ascii, down);
1311 q = CL_VM_InputEvent(down, key, ascii);
1312 // ignore key repeats on binds and only send the bind if the event hasnt been already processed by csqc
1315 if(keydown[key] == 1 && down)
1317 // button commands add keynum as a parm
1319 Cbuf_AddText (va("%s %i\n", bind, key));
1322 Cbuf_AddText (bind);
1323 Cbuf_AddText ("\n");
1325 } else if(bind[0] == '+' && !down && keydown[key] == 0)
1326 Cbuf_AddText(va("-%s %i\n", bind + 1, key));
1330 Con_Printf ("Key_Event: Bad key_dest\n");
1340 Key_ClearStates (void)
1342 memset(keydown, 0, sizeof(keydown));