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
27 cvar_t con_closeontoggleconsole = {CVAR_SAVE, "con_closeontoggleconsole","1", "allows toggleconsole binds to close the console as well; when set to 2, this even works when not at the start of the line in console input; when set to 3, this works even if the toggleconsole key is the color tag"};
30 key up events are sent even if in console mode
33 char key_line[MAX_INPUTLINE];
35 qboolean key_insert = true; // insert key toggle (for editing)
37 int key_consoleactive;
38 char *keybindings[MAX_BINDMAPS][MAX_KEYS];
41 char history_savedline[MAX_INPUTLINE];
42 char history_searchstring[MAX_INPUTLINE];
43 qboolean history_matchfound = false;
46 extern cvar_t con_textsize;
49 static void Key_History_Init(void)
52 ConBuffer_Init(&history, HIST_TEXTSIZE, HIST_MAXLINES, zonemempool);
54 historyfile = FS_OpenRealFile("darkplaces_history.txt", "rb", false); // rb to handle unix line endings on windows too
57 char buf[MAX_INPUTLINE];
64 c = FS_Getc(historyfile);
65 if(c < 0 || c == 0 || c == '\r' || c == '\n')
70 ConBuffer_AddLine(&history, buf, bufpos, 0);
78 if(bufpos < MAX_INPUTLINE - 1)
83 FS_Close(historyfile);
89 static void Key_History_Shutdown(void)
91 // TODO write history to a file
93 qfile_t *historyfile = FS_OpenRealFile("darkplaces_history.txt", "w", false);
97 for(i = 0; i < CONBUFFER_LINES_COUNT(&history); ++i)
98 FS_Printf(historyfile, "%s\n", ConBuffer_GetLine(&history, i));
99 FS_Close(historyfile);
102 ConBuffer_Shutdown(&history);
105 static void Key_History_Push(void)
107 if(key_line[1]) // empty?
108 if(strcmp(key_line, "]quit")) // putting these into the history just sucks
109 if(strncmp(key_line, "]quit ", 6)) // putting these into the history just sucks
110 ConBuffer_AddLine(&history, key_line + 1, strlen(key_line) - 1, 0);
111 Con_Printf("%s\n", key_line); // don't mark empty lines as history
113 if (history_matchfound)
114 history_matchfound = false;
117 qboolean Key_History_Get_foundCommand(void)
119 if (!history_matchfound)
121 strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
122 key_linepos = strlen(key_line);
123 history_matchfound = false;
127 static void Key_History_Up(void)
129 if(history_line == -1) // editing the "new" line
130 strlcpy(history_savedline, key_line + 1, sizeof(history_savedline));
132 if (Key_History_Get_foundCommand())
135 if(history_line == -1)
137 history_line = CONBUFFER_LINES_COUNT(&history) - 1;
138 if(history_line != -1)
140 strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
141 key_linepos = strlen(key_line);
144 else if(history_line > 0)
146 --history_line; // this also does -1 -> 0, so it is good
147 strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
148 key_linepos = strlen(key_line);
152 static void Key_History_Down(void)
154 if(history_line == -1) // editing the "new" line
157 if (Key_History_Get_foundCommand())
160 if(history_line < CONBUFFER_LINES_COUNT(&history) - 1)
163 strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
168 strlcpy(key_line + 1, history_savedline, sizeof(key_line) - 1);
171 key_linepos = strlen(key_line);
174 static void Key_History_First(void)
176 if(history_line == -1) // editing the "new" line
177 strlcpy(history_savedline, key_line + 1, sizeof(history_savedline));
179 if (CONBUFFER_LINES_COUNT(&history) > 0)
182 strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
183 key_linepos = strlen(key_line);
187 static void Key_History_Last(void)
189 if(history_line == -1) // editing the "new" line
190 strlcpy(history_savedline, key_line + 1, sizeof(history_savedline));
192 if (CONBUFFER_LINES_COUNT(&history) > 0)
194 history_line = CONBUFFER_LINES_COUNT(&history) - 1;
195 strlcpy(key_line + 1, ConBuffer_GetLine(&history, history_line), sizeof(key_line) - 1);
196 key_linepos = strlen(key_line);
200 static void Key_History_Find_Backwards(void)
203 const char *partial = key_line + 1;
204 size_t digits = strlen(va("%i", HIST_MAXLINES));
206 if (history_line == -1) // editing the "new" line
207 strlcpy(history_savedline, key_line + 1, sizeof(history_savedline));
209 if (strcmp(key_line + 1, history_searchstring)) // different string? Start a new search
211 strlcpy(history_searchstring, key_line + 1, sizeof(history_searchstring));
212 i = CONBUFFER_LINES_COUNT(&history) - 1;
214 else if (history_line == -1)
215 i = CONBUFFER_LINES_COUNT(&history) - 1;
217 i = history_line - 1;
221 else if (!( strchr(partial, '*') || strchr(partial, '?') )) // no pattern?
222 partial = va("*%s*", partial);
225 if (matchpattern_with_separator(ConBuffer_GetLine(&history, i), partial, true, "", false))
227 Con_Printf("^2%*i^7 %s\n", (int)digits, i+1, ConBuffer_GetLine(&history, i));
229 history_matchfound = true;
234 static void Key_History_Find_Forwards(void)
237 const char *partial = key_line + 1;
238 size_t digits = strlen(va("%i", HIST_MAXLINES));
240 if (history_line == -1) // editing the "new" line
243 if (strcmp(key_line + 1, history_searchstring)) // different string? Start a new search
245 strlcpy(history_searchstring, key_line + 1, sizeof(history_searchstring));
248 else i = history_line + 1;
252 else if (!( strchr(partial, '*') || strchr(partial, '?') )) // no pattern?
253 partial = va("*%s*", partial);
255 for ( ; i < CONBUFFER_LINES_COUNT(&history); i++)
256 if (matchpattern_with_separator(ConBuffer_GetLine(&history, i), partial, true, "", false))
258 Con_Printf("^2%*i^7 %s\n", (int)digits, i+1, ConBuffer_GetLine(&history, i));
260 history_matchfound = true;
265 static void Key_History_Find_All(void)
267 const char *partial = key_line + 1;
269 size_t digits = strlen(va("%i", HIST_MAXLINES));
270 Con_Printf("History commands containing \"%s\":\n", key_line + 1);
274 else if (!( strchr(partial, '*') || strchr(partial, '?') )) // no pattern?
275 partial = va("*%s*", partial);
277 for (i=0; i<CONBUFFER_LINES_COUNT(&history); i++)
278 if (matchpattern_with_separator(ConBuffer_GetLine(&history, i), partial, true, "", false))
280 Con_Printf("%s%*i^7 %s\n", (i == history_line) ? "^2" : "^3", (int)digits, i+1, ConBuffer_GetLine(&history, i));
283 Con_Printf("%i result%s\n\n", count, (count != 1) ? "s" : "");
286 static void Key_History_f(void)
288 char *errchar = NULL;
290 size_t digits = strlen(va("%i", HIST_MAXLINES));
294 if (!strcmp(Cmd_Argv (1), "-c"))
296 ConBuffer_Clear(&history);
299 i = strtol(Cmd_Argv (1), &errchar, 0);
300 if ((i < 0) || (i > CONBUFFER_LINES_COUNT(&history)) || (errchar && *errchar))
303 i = CONBUFFER_LINES_COUNT(&history) - i;
306 for ( ; i<CONBUFFER_LINES_COUNT(&history); i++)
307 Con_Printf("^3%*i^7 %s\n", (int)digits, i+1, ConBuffer_GetLine(&history, i));
311 static int key_bmap, key_bmap2;
312 static unsigned char keydown[MAX_KEYS]; // 0 = up, 1 = down, 2 = repeating
314 typedef struct keyname_s
321 static const keyname_t keynames[] = {
324 {"ESCAPE", K_ESCAPE},
327 // spacer so it lines up with keys.h
329 {"BACKSPACE", K_BACKSPACE},
330 {"UPARROW", K_UPARROW},
331 {"DOWNARROW", K_DOWNARROW},
332 {"LEFTARROW", K_LEFTARROW},
333 {"RIGHTARROW", K_RIGHTARROW},
361 {"NUMLOCK", K_NUMLOCK},
362 {"CAPSLOCK", K_CAPSLOCK},
363 {"SCROLLOCK", K_SCROLLOCK},
365 {"KP_INS", K_KP_INS },
367 {"KP_END", K_KP_END },
369 {"KP_DOWNARROW", K_KP_DOWNARROW },
371 {"KP_PGDN", K_KP_PGDN },
373 {"KP_LEFTARROW", K_KP_LEFTARROW },
376 {"KP_RIGHTARROW", K_KP_RIGHTARROW },
378 {"KP_HOME", K_KP_HOME },
380 {"KP_UPARROW", K_KP_UPARROW },
382 {"KP_PGUP", K_KP_PGUP },
384 {"KP_DEL", K_KP_DEL },
385 {"KP_PERIOD", K_KP_PERIOD},
386 {"KP_SLASH", K_KP_SLASH },
387 {"KP_DIVIDE", K_KP_DIVIDE},
388 {"KP_MULTIPLY", K_KP_MULTIPLY},
389 {"KP_MINUS", K_KP_MINUS},
390 {"KP_PLUS", K_KP_PLUS},
391 {"KP_ENTER", K_KP_ENTER},
392 {"KP_EQUALS", K_KP_EQUALS},
394 {"PRINTSCREEN", K_PRINTSCREEN},
398 {"MOUSE1", K_MOUSE1},
400 {"MOUSE2", K_MOUSE2},
401 {"MOUSE3", K_MOUSE3},
402 {"MWHEELUP", K_MWHEELUP},
403 {"MWHEELDOWN", K_MWHEELDOWN},
404 {"MOUSE4", K_MOUSE4},
405 {"MOUSE5", K_MOUSE5},
406 {"MOUSE6", K_MOUSE6},
407 {"MOUSE7", K_MOUSE7},
408 {"MOUSE8", K_MOUSE8},
409 {"MOUSE9", K_MOUSE9},
410 {"MOUSE10", K_MOUSE10},
411 {"MOUSE11", K_MOUSE11},
412 {"MOUSE12", K_MOUSE12},
413 {"MOUSE13", K_MOUSE13},
414 {"MOUSE14", K_MOUSE14},
415 {"MOUSE15", K_MOUSE15},
416 {"MOUSE16", K_MOUSE16},
476 {"X360_DPAD_UP", K_X360_DPAD_UP},
477 {"X360_DPAD_DOWN", K_X360_DPAD_DOWN},
478 {"X360_DPAD_LEFT", K_X360_DPAD_LEFT},
479 {"X360_DPAD_RIGHT", K_X360_DPAD_RIGHT},
480 {"X360_START", K_X360_START},
481 {"X360_BACK", K_X360_BACK},
482 {"X360_LEFT_THUMB", K_X360_LEFT_THUMB},
483 {"X360_RIGHT_THUMB", K_X360_RIGHT_THUMB},
484 {"X360_LEFT_SHOULDER", K_X360_LEFT_SHOULDER},
485 {"X360_RIGHT_SHOULDER", K_X360_RIGHT_SHOULDER},
486 {"X360_A", K_X360_A},
487 {"X360_B", K_X360_B},
488 {"X360_X", K_X360_X},
489 {"X360_Y", K_X360_Y},
490 {"X360_LEFT_TRIGGER", K_X360_LEFT_TRIGGER},
491 {"X360_RIGHT_TRIGGER", K_X360_RIGHT_TRIGGER},
492 {"X360_LEFT_THUMB_UP", K_X360_LEFT_THUMB_UP},
493 {"X360_LEFT_THUMB_DOWN", K_X360_LEFT_THUMB_DOWN},
494 {"X360_LEFT_THUMB_LEFT", K_X360_LEFT_THUMB_LEFT},
495 {"X360_LEFT_THUMB_RIGHT", K_X360_LEFT_THUMB_RIGHT},
496 {"X360_RIGHT_THUMB_UP", K_X360_RIGHT_THUMB_UP},
497 {"X360_RIGHT_THUMB_DOWN", K_X360_RIGHT_THUMB_DOWN},
498 {"X360_RIGHT_THUMB_LEFT", K_X360_RIGHT_THUMB_LEFT},
499 {"X360_RIGHT_THUMB_RIGHT", K_X360_RIGHT_THUMB_RIGHT},
501 {"SEMICOLON", ';'}, // because a raw semicolon separates commands
505 {"APOSTROPHE", '\''},
506 {"BACKSLASH", '\\'}, // because a raw backslash is used for special characters
508 {"MIDINOTE0", K_MIDINOTE0},
509 {"MIDINOTE1", K_MIDINOTE1},
510 {"MIDINOTE2", K_MIDINOTE2},
511 {"MIDINOTE3", K_MIDINOTE3},
512 {"MIDINOTE4", K_MIDINOTE4},
513 {"MIDINOTE5", K_MIDINOTE5},
514 {"MIDINOTE6", K_MIDINOTE6},
515 {"MIDINOTE7", K_MIDINOTE7},
516 {"MIDINOTE8", K_MIDINOTE8},
517 {"MIDINOTE9", K_MIDINOTE9},
518 {"MIDINOTE10", K_MIDINOTE10},
519 {"MIDINOTE11", K_MIDINOTE11},
520 {"MIDINOTE12", K_MIDINOTE12},
521 {"MIDINOTE13", K_MIDINOTE13},
522 {"MIDINOTE14", K_MIDINOTE14},
523 {"MIDINOTE15", K_MIDINOTE15},
524 {"MIDINOTE16", K_MIDINOTE16},
525 {"MIDINOTE17", K_MIDINOTE17},
526 {"MIDINOTE18", K_MIDINOTE18},
527 {"MIDINOTE19", K_MIDINOTE19},
528 {"MIDINOTE20", K_MIDINOTE20},
529 {"MIDINOTE21", K_MIDINOTE21},
530 {"MIDINOTE22", K_MIDINOTE22},
531 {"MIDINOTE23", K_MIDINOTE23},
532 {"MIDINOTE24", K_MIDINOTE24},
533 {"MIDINOTE25", K_MIDINOTE25},
534 {"MIDINOTE26", K_MIDINOTE26},
535 {"MIDINOTE27", K_MIDINOTE27},
536 {"MIDINOTE28", K_MIDINOTE28},
537 {"MIDINOTE29", K_MIDINOTE29},
538 {"MIDINOTE30", K_MIDINOTE30},
539 {"MIDINOTE31", K_MIDINOTE31},
540 {"MIDINOTE32", K_MIDINOTE32},
541 {"MIDINOTE33", K_MIDINOTE33},
542 {"MIDINOTE34", K_MIDINOTE34},
543 {"MIDINOTE35", K_MIDINOTE35},
544 {"MIDINOTE36", K_MIDINOTE36},
545 {"MIDINOTE37", K_MIDINOTE37},
546 {"MIDINOTE38", K_MIDINOTE38},
547 {"MIDINOTE39", K_MIDINOTE39},
548 {"MIDINOTE40", K_MIDINOTE40},
549 {"MIDINOTE41", K_MIDINOTE41},
550 {"MIDINOTE42", K_MIDINOTE42},
551 {"MIDINOTE43", K_MIDINOTE43},
552 {"MIDINOTE44", K_MIDINOTE44},
553 {"MIDINOTE45", K_MIDINOTE45},
554 {"MIDINOTE46", K_MIDINOTE46},
555 {"MIDINOTE47", K_MIDINOTE47},
556 {"MIDINOTE48", K_MIDINOTE48},
557 {"MIDINOTE49", K_MIDINOTE49},
558 {"MIDINOTE50", K_MIDINOTE50},
559 {"MIDINOTE51", K_MIDINOTE51},
560 {"MIDINOTE52", K_MIDINOTE52},
561 {"MIDINOTE53", K_MIDINOTE53},
562 {"MIDINOTE54", K_MIDINOTE54},
563 {"MIDINOTE55", K_MIDINOTE55},
564 {"MIDINOTE56", K_MIDINOTE56},
565 {"MIDINOTE57", K_MIDINOTE57},
566 {"MIDINOTE58", K_MIDINOTE58},
567 {"MIDINOTE59", K_MIDINOTE59},
568 {"MIDINOTE60", K_MIDINOTE60},
569 {"MIDINOTE61", K_MIDINOTE61},
570 {"MIDINOTE62", K_MIDINOTE62},
571 {"MIDINOTE63", K_MIDINOTE63},
572 {"MIDINOTE64", K_MIDINOTE64},
573 {"MIDINOTE65", K_MIDINOTE65},
574 {"MIDINOTE66", K_MIDINOTE66},
575 {"MIDINOTE67", K_MIDINOTE67},
576 {"MIDINOTE68", K_MIDINOTE68},
577 {"MIDINOTE69", K_MIDINOTE69},
578 {"MIDINOTE70", K_MIDINOTE70},
579 {"MIDINOTE71", K_MIDINOTE71},
580 {"MIDINOTE72", K_MIDINOTE72},
581 {"MIDINOTE73", K_MIDINOTE73},
582 {"MIDINOTE74", K_MIDINOTE74},
583 {"MIDINOTE75", K_MIDINOTE75},
584 {"MIDINOTE76", K_MIDINOTE76},
585 {"MIDINOTE77", K_MIDINOTE77},
586 {"MIDINOTE78", K_MIDINOTE78},
587 {"MIDINOTE79", K_MIDINOTE79},
588 {"MIDINOTE80", K_MIDINOTE80},
589 {"MIDINOTE81", K_MIDINOTE81},
590 {"MIDINOTE82", K_MIDINOTE82},
591 {"MIDINOTE83", K_MIDINOTE83},
592 {"MIDINOTE84", K_MIDINOTE84},
593 {"MIDINOTE85", K_MIDINOTE85},
594 {"MIDINOTE86", K_MIDINOTE86},
595 {"MIDINOTE87", K_MIDINOTE87},
596 {"MIDINOTE88", K_MIDINOTE88},
597 {"MIDINOTE89", K_MIDINOTE89},
598 {"MIDINOTE90", K_MIDINOTE90},
599 {"MIDINOTE91", K_MIDINOTE91},
600 {"MIDINOTE92", K_MIDINOTE92},
601 {"MIDINOTE93", K_MIDINOTE93},
602 {"MIDINOTE94", K_MIDINOTE94},
603 {"MIDINOTE95", K_MIDINOTE95},
604 {"MIDINOTE96", K_MIDINOTE96},
605 {"MIDINOTE97", K_MIDINOTE97},
606 {"MIDINOTE98", K_MIDINOTE98},
607 {"MIDINOTE99", K_MIDINOTE99},
608 {"MIDINOTE100", K_MIDINOTE100},
609 {"MIDINOTE101", K_MIDINOTE101},
610 {"MIDINOTE102", K_MIDINOTE102},
611 {"MIDINOTE103", K_MIDINOTE103},
612 {"MIDINOTE104", K_MIDINOTE104},
613 {"MIDINOTE105", K_MIDINOTE105},
614 {"MIDINOTE106", K_MIDINOTE106},
615 {"MIDINOTE107", K_MIDINOTE107},
616 {"MIDINOTE108", K_MIDINOTE108},
617 {"MIDINOTE109", K_MIDINOTE109},
618 {"MIDINOTE110", K_MIDINOTE110},
619 {"MIDINOTE111", K_MIDINOTE111},
620 {"MIDINOTE112", K_MIDINOTE112},
621 {"MIDINOTE113", K_MIDINOTE113},
622 {"MIDINOTE114", K_MIDINOTE114},
623 {"MIDINOTE115", K_MIDINOTE115},
624 {"MIDINOTE116", K_MIDINOTE116},
625 {"MIDINOTE117", K_MIDINOTE117},
626 {"MIDINOTE118", K_MIDINOTE118},
627 {"MIDINOTE119", K_MIDINOTE119},
628 {"MIDINOTE120", K_MIDINOTE120},
629 {"MIDINOTE121", K_MIDINOTE121},
630 {"MIDINOTE122", K_MIDINOTE122},
631 {"MIDINOTE123", K_MIDINOTE123},
632 {"MIDINOTE124", K_MIDINOTE124},
633 {"MIDINOTE125", K_MIDINOTE125},
634 {"MIDINOTE126", K_MIDINOTE126},
635 {"MIDINOTE127", K_MIDINOTE127},
641 ==============================================================================
643 LINE TYPING INTO THE CONSOLE
645 ==============================================================================
649 Key_ClearEditLine (int edit_line)
651 memset (key_line, '\0', sizeof(key_line));
658 Interactive line editing and console scrollback
662 Key_Console (int key, int unicode)
664 // LordHavoc: copied most of this from Q2 to improve keyboard handling
691 case K_KP_RIGHTARROW:
711 if ((key == 'v' && keydown[K_CTRL]) || ((key == K_INS || key == K_KP_INS) && keydown[K_SHIFT]))
714 if ((cbd = Sys_GetClipboardData()) != 0)
721 if (*p == '\r' && *(p+1) == '\n')
726 else if (*p == '\n' || *p == '\r' || *p == '\b')
731 strtok(cbd, "\n\r\b");
733 i = (int)strlen(cbd);
734 if (i + key_linepos >= MAX_INPUTLINE)
735 i= MAX_INPUTLINE - key_linepos - 1;
738 // terencehill: insert the clipboard text between the characters of the line
740 char *temp = (char *) Z_Malloc(MAX_INPUTLINE);
743 if ( key_linepos < (int)strlen(key_line) )
744 strlcpy(temp, key_line + key_linepos, (int)strlen(key_line) - key_linepos +1);
745 key_line[key_linepos] = 0;
746 strlcat(key_line, cbd, sizeof(key_line));
748 strlcat(key_line, temp, sizeof(key_line));
752 // blub: I'm changing this to use memmove() like the rest of the code does.
754 memmove(key_line + key_linepos + i, key_line + key_linepos, sizeof(key_line) - key_linepos - i);
755 memcpy(key_line + key_linepos, cbd, i);
763 if (key == 'l' && keydown[K_CTRL])
765 Cbuf_AddText ("clear\n");
769 if (key == 'u' && keydown[K_CTRL]) // like vi/readline ^u: delete currently edited line
778 if (key == 'q' && keydown[K_CTRL]) // like zsh ^q: push line to history, don't execute, and clear
788 if (key == K_ENTER || key == K_KP_ENTER)
790 Cbuf_AddText (key_line+1); // skip the ]
794 key_line[1] = 0; // EvilTypeGuy: null terminate
796 // force an update, because the command may take some time
797 if (cls.state == ca_disconnected)
804 if(keydown[K_CTRL]) // append to the cvar its value
806 int cvar_len, cvar_str_len, chars_to_move;
808 char cvar[MAX_INPUTLINE];
809 const char *cvar_str;
811 // go to the start of the variable
814 k = key_line[key_linepos];
815 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
820 // save the variable name in cvar
821 for(cvar_len=0; (k = key_line[key_linepos + cvar_len]) != 0; cvar_len++)
823 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
831 // go to the end of the cvar
832 key_linepos += cvar_len;
834 // save the content of the variable in cvar_str
835 cvar_str = Cvar_VariableString(cvar);
836 cvar_str_len = strlen(cvar_str);
840 // insert space and cvar_str in key_line
841 chars_to_move = strlen(&key_line[key_linepos]);
842 if (key_linepos + 1 + cvar_str_len + chars_to_move < MAX_INPUTLINE)
845 memmove(&key_line[key_linepos + 1 + cvar_str_len], &key_line[key_linepos], chars_to_move);
846 key_line[key_linepos++] = ' ';
847 memcpy(&key_line[key_linepos], cvar_str, cvar_str_len);
848 key_linepos += cvar_str_len;
849 key_line[key_linepos + chars_to_move] = 0;
852 Con_Printf("Couldn't append cvar value, edit line too long.\n");
855 // Enhanced command completion
856 // by EvilTypeGuy eviltypeguy@qeradiant.com
857 // Thanks to Fett, Taniwha
858 Con_CompleteCommandLine();
862 // Advanced Console Editing by Radix radix@planetquake.com
863 // Added/Modified by EvilTypeGuy eviltypeguy@qeradiant.com
865 // Enhanced by terencehill
867 // move cursor to the previous character
868 if (key == K_LEFTARROW || key == K_KP_LEFTARROW)
872 if(keydown[K_CTRL]) // move cursor to the previous word
878 if(pos) // skip all "; ' after the word
882 if (!(k == '\"' || k == ';' || k == ' ' || k == '\''))
890 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
893 key_linepos = pos + 1;
895 else if(keydown[K_SHIFT]) // move cursor to the previous character ignoring colors
899 pos = u8_prevbyte(key_line+1, key_linepos-1) + 1; // do NOT give the ']' to u8_prevbyte
901 if(pos-1 > 0 && key_line[pos-1] == STRING_COLOR_TAG && isdigit(key_line[pos]))
903 else if(pos-4 > 0 && key_line[pos-4] == STRING_COLOR_TAG && key_line[pos-3] == STRING_COLOR_RGB_TAG_CHAR
904 && isxdigit(key_line[pos-2]) && isxdigit(key_line[pos-1]) && isxdigit(key_line[pos]))
908 if(pos-1 > 0 && key_line[pos-1] == STRING_COLOR_TAG && key_line[pos] == STRING_COLOR_TAG) // consider ^^ as a character
913 // we need to move to the beginning of the character when in a wide character:
914 u8_charidx(key_line, pos + 1, &inchar);
915 key_linepos = pos + 1 - inchar;
919 key_linepos = u8_prevbyte(key_line+1, key_linepos-1) + 1; // do NOT give the ']' to u8_prevbyte
924 // delete char before cursor
925 if (key == K_BACKSPACE || (key == 'h' && keydown[K_CTRL]))
929 int newpos = u8_prevbyte(key_line+1, key_linepos-1) + 1; // do NOT give the ']' to u8_prevbyte
930 strlcpy(key_line + newpos, key_line + key_linepos, sizeof(key_line) + 1 - key_linepos);
931 key_linepos = newpos;
936 // delete char on cursor
937 if (key == K_DEL || key == K_KP_DEL)
940 linelen = strlen(key_line);
941 if (key_linepos < (int)linelen)
942 memmove(key_line + key_linepos, key_line + key_linepos + u8_bytelen(key_line + key_linepos, 1), linelen - key_linepos);
947 // move cursor to the next character
948 if (key == K_RIGHTARROW || key == K_KP_RIGHTARROW)
950 if (key_linepos >= (int)strlen(key_line))
952 if(keydown[K_CTRL]) // move cursor to the next word
956 len = (int)strlen(key_line);
962 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
966 if (pos < len) // skip all "; ' after the word
970 if (!(k == '\"' || k == ';' || k == ' ' || k == '\''))
975 else if(keydown[K_SHIFT]) // move cursor to the next character ignoring colors
978 len = (int)strlen(key_line);
981 // go beyond all initial consecutive color tags, if any
983 while (key_line[pos] == STRING_COLOR_TAG)
985 if(isdigit(key_line[pos+1]))
987 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]))
994 if (key_line[pos] == STRING_COLOR_TAG && key_line[pos+1] == STRING_COLOR_TAG) // consider ^^ as a character
996 pos += u8_bytelen(key_line + pos, 1);
998 // now go beyond all next consecutive color tags, if any
1000 while (key_line[pos] == STRING_COLOR_TAG)
1002 if(isdigit(key_line[pos+1]))
1004 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]))
1012 key_linepos += u8_bytelen(key_line + key_linepos, 1);
1016 if (key == K_INS || key == K_KP_INS) // toggle insert mode
1022 // End Advanced Console Editing
1024 if (key == K_UPARROW || key == K_KP_UPARROW || (key == 'p' && keydown[K_CTRL]))
1030 if (key == K_DOWNARROW || key == K_KP_DOWNARROW || (key == 'n' && keydown[K_CTRL]))
1035 // ~1.0795 = 82/76 using con_textsize 64 76 is height of the char, 6 is the distance between 2 lines
1037 if (keydown[K_CTRL])
1039 // prints all the matching commands
1042 Key_History_Find_All();
1045 // Search forwards/backwards, pointing the history's index to the
1046 // matching command but without fetching it to let one continue the search.
1047 // To fetch it, it suffices to just press UP or DOWN.
1050 if (keydown[K_SHIFT])
1051 Key_History_Find_Forwards();
1053 Key_History_Find_Backwards();
1056 // go to the last/first command of the history
1059 Key_History_First();
1069 if (key == K_PGUP || key == K_KP_PGUP)
1073 con_backscroll += ((vid_conheight.integer >> 2) / con_textsize.integer)-1;
1076 con_backscroll += ((vid_conheight.integer >> 1) / con_textsize.integer)-3;
1080 if (key == K_PGDN || key == K_KP_PGDN)
1084 con_backscroll -= ((vid_conheight.integer >> 2) / con_textsize.integer)-1;
1087 con_backscroll -= ((vid_conheight.integer >> 1) / con_textsize.integer)-3;
1091 if (key == K_MWHEELUP)
1094 con_backscroll += 1;
1095 else if(keydown[K_SHIFT])
1096 con_backscroll += ((vid_conheight.integer >> 2) / con_textsize.integer)-1;
1098 con_backscroll += 5;
1102 if (key == K_MWHEELDOWN)
1105 con_backscroll -= 1;
1106 else if(keydown[K_SHIFT])
1107 con_backscroll -= ((vid_conheight.integer >> 2) / con_textsize.integer)-1;
1109 con_backscroll -= 5;
1113 if (keydown[K_CTRL])
1116 if (key == '+' || key == K_KP_PLUS)
1118 if (con_textsize.integer < 128)
1119 Cvar_SetValueQuick(&con_textsize, con_textsize.integer + 1);
1123 if (key == '-' || key == K_KP_MINUS)
1125 if (con_textsize.integer > 1)
1126 Cvar_SetValueQuick(&con_textsize, con_textsize.integer - 1);
1130 if (key == '0' || key == K_KP_INS)
1132 Cvar_SetValueQuick(&con_textsize, atoi(Cvar_VariableDefString("con_textsize")));
1137 if (key == K_HOME || key == K_KP_HOME)
1139 if (keydown[K_CTRL])
1140 con_backscroll = CON_TEXTSIZE;
1146 if (key == K_END || key == K_KP_END)
1148 if (keydown[K_CTRL])
1151 key_linepos = (int)strlen(key_line);
1159 if (key_linepos < MAX_INPUTLINE-1)
1164 blen = u8_fromchar(unicode, buf, sizeof(buf));
1167 len = (int)strlen(&key_line[key_linepos]);
1168 // check insert mode, or always insert if at end of line
1169 if (key_insert || len == 0)
1171 // can't use strcpy to move string to right
1173 //memmove(&key_line[key_linepos + u8_bytelen(key_line + key_linepos, 1)], &key_line[key_linepos], len);
1174 memmove(&key_line[key_linepos + blen], &key_line[key_linepos], len);
1176 memcpy(key_line + key_linepos, buf, blen);
1177 key_linepos += blen;
1178 //key_linepos += u8_fromchar(unicode, key_line + key_linepos, sizeof(key_line) - key_linepos - 1);
1179 //key_line[key_linepos] = ascii;
1184 //============================================================================
1187 char chat_buffer[MAX_INPUTLINE];
1188 unsigned int chat_bufferlen = 0;
1190 extern int Nicks_CompleteChatLine(char *buffer, size_t size, unsigned int pos);
1193 Key_Message (int key, int ascii)
1195 if (key == K_ENTER || ascii == 10 || ascii == 13)
1198 Cmd_ExecuteString(chat_buffer, src_command); // not Cbuf_AddText to allow semiclons in args; however, this allows no variables then. Use aliases!
1200 Cmd_ForwardStringToServer(va("%s %s", chat_mode ? "say_team" : "say ", chat_buffer));
1202 key_dest = key_game;
1208 // TODO add support for arrow keys and simple editing
1210 if (key == K_ESCAPE) {
1211 key_dest = key_game;
1217 if (key == K_BACKSPACE) {
1218 if (chat_bufferlen) {
1219 chat_bufferlen = u8_prevbyte(chat_buffer, chat_bufferlen);
1220 chat_buffer[chat_bufferlen] = 0;
1226 chat_bufferlen = Nicks_CompleteChatLine(chat_buffer, sizeof(chat_buffer), chat_bufferlen);
1230 // ctrl+key generates an ascii value < 32 and shows a char from the charmap
1231 if (ascii > 0 && ascii < 32 && utf8_enable.integer)
1232 ascii = 0xE000 + ascii;
1234 if (chat_bufferlen == sizeof (chat_buffer) - 1)
1238 return; // non printable
1240 chat_bufferlen += u8_fromchar(ascii, chat_buffer+chat_bufferlen, sizeof(chat_buffer) - chat_bufferlen - 1);
1242 //chat_buffer[chat_bufferlen++] = ascii;
1243 //chat_buffer[chat_bufferlen] = 0;
1246 //============================================================================
1251 Returns a key number to be used to index keybindings[] by looking at
1252 the given string. Single ascii characters return themselves, while
1253 the K_* names are matched up.
1257 Key_StringToKeynum (const char *str)
1259 const keyname_t *kn;
1261 if (!str || !str[0])
1264 return tolower(str[0]);
1266 for (kn = keynames; kn->name; kn++) {
1267 if (!strcasecmp (str, kn->name))
1275 Returns a string (either a single ascii char, or a K_* name) for the
1277 FIXME: handle quote special (general escape sequence?)
1281 Key_KeynumToString (int keynum)
1283 const keyname_t *kn;
1284 static char tinystr[2];
1286 // -1 is an invalid code
1288 return "<KEY NOT FOUND>";
1290 // search overrides first, because some characters are special
1291 for (kn = keynames; kn->name; kn++)
1292 if (keynum == kn->keynum)
1295 // if it is printable, output it as a single character
1296 if (keynum > 32 && keynum < 256)
1298 tinystr[0] = keynum;
1303 // if it is not overridden and not printable, we don't know what to do with it
1304 return "<UNKNOWN KEYNUM>";
1309 Key_SetBinding (int keynum, int bindmap, const char *binding)
1314 if (keynum == -1 || keynum >= MAX_KEYS)
1316 if ((bindmap < 0) || (bindmap >= MAX_BINDMAPS))
1319 // free old bindings
1320 if (keybindings[bindmap][keynum]) {
1321 Z_Free (keybindings[bindmap][keynum]);
1322 keybindings[bindmap][keynum] = NULL;
1324 if(!binding[0]) // make "" binds be removed --blub
1326 // allocate memory for new binding
1327 l = strlen (binding);
1328 newbinding = (char *)Z_Malloc (l + 1);
1329 memcpy (newbinding, binding, l + 1);
1331 keybindings[bindmap][keynum] = newbinding;
1335 void Key_GetBindMap(int *fg, int *bg)
1343 qboolean Key_SetBindMap(int fg, int bg)
1345 if(fg >= MAX_BINDMAPS)
1347 if(bg >= MAX_BINDMAPS)
1357 Key_In_Unbind_f (void)
1360 char *errchar = NULL;
1362 if (Cmd_Argc () != 3) {
1363 Con_Print("in_unbind <bindmap> <key> : remove commands from a key\n");
1367 m = strtol(Cmd_Argv (1), &errchar, 0);
1368 if ((m < 0) || (m >= MAX_BINDMAPS) || (errchar && *errchar)) {
1369 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
1373 b = Key_StringToKeynum (Cmd_Argv (2));
1375 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (2));
1379 if(!Key_SetBinding (b, m, ""))
1380 Con_Printf("Key_SetBinding failed for unknown reason\n");
1384 Key_In_Bind_f (void)
1387 char cmd[MAX_INPUTLINE];
1388 char *errchar = NULL;
1392 if (c != 3 && c != 4) {
1393 Con_Print("in_bind <bindmap> <key> [command] : attach a command to a key\n");
1397 m = strtol(Cmd_Argv (1), &errchar, 0);
1398 if ((m < 0) || (m >= MAX_BINDMAPS) || (errchar && *errchar)) {
1399 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
1403 b = Key_StringToKeynum (Cmd_Argv (2));
1404 if (b == -1 || b >= MAX_KEYS) {
1405 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (2));
1410 if (keybindings[m][b])
1411 Con_Printf("\"%s\" = \"%s\"\n", Cmd_Argv (2), keybindings[m][b]);
1413 Con_Printf("\"%s\" is not bound\n", Cmd_Argv (2));
1416 // copy the rest of the command line
1417 cmd[0] = 0; // start out with a null string
1418 for (i = 3; i < c; i++) {
1419 strlcat (cmd, Cmd_Argv (i), sizeof (cmd));
1421 strlcat (cmd, " ", sizeof (cmd));
1424 if(!Key_SetBinding (b, m, cmd))
1425 Con_Printf("Key_SetBinding failed for unknown reason\n");
1429 Key_In_Bindmap_f (void)
1432 char *errchar = NULL;
1437 Con_Print("in_bindmap <bindmap> <fallback>: set current bindmap and fallback\n");
1441 m1 = strtol(Cmd_Argv (1), &errchar, 0);
1442 if ((m1 < 0) || (m1 >= MAX_BINDMAPS) || (errchar && *errchar)) {
1443 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
1447 m2 = strtol(Cmd_Argv (2), &errchar, 0);
1448 if ((m2 < 0) || (m2 >= MAX_BINDMAPS) || (errchar && *errchar)) {
1449 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(2));
1462 if (Cmd_Argc () != 2) {
1463 Con_Print("unbind <key> : remove commands from a key\n");
1467 b = Key_StringToKeynum (Cmd_Argv (1));
1469 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (1));
1473 if(!Key_SetBinding (b, 0, ""))
1474 Con_Printf("Key_SetBinding failed for unknown reason\n");
1478 Key_Unbindall_f (void)
1482 for (j = 0; j < MAX_BINDMAPS; j++)
1483 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
1484 if (keybindings[j][i])
1485 Key_SetBinding (i, j, "");
1489 Key_PrintBindList(int j)
1491 char bindbuf[MAX_INPUTLINE];
1495 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
1497 p = keybindings[j][i];
1500 Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\", false);
1502 Con_Printf("^2%s ^7= \"%s\"\n", Key_KeynumToString (i), bindbuf);
1504 Con_Printf("^3bindmap %d: ^2%s ^7= \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
1510 Key_In_BindList_f (void)
1513 char *errchar = NULL;
1517 m = strtol(Cmd_Argv(1), &errchar, 0);
1518 if ((m < 0) || (m >= MAX_BINDMAPS) || (errchar && *errchar)) {
1519 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
1522 Key_PrintBindList(m);
1526 for (m = 0; m < MAX_BINDMAPS; m++)
1527 Key_PrintBindList(m);
1532 Key_BindList_f (void)
1534 Key_PrintBindList(0);
1541 char cmd[MAX_INPUTLINE];
1545 if (c != 2 && c != 3) {
1546 Con_Print("bind <key> [command] : attach a command to a key\n");
1549 b = Key_StringToKeynum (Cmd_Argv (1));
1550 if (b == -1 || b >= MAX_KEYS) {
1551 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (1));
1556 if (keybindings[0][b])
1557 Con_Printf("\"%s\" = \"%s\"\n", Cmd_Argv (1), keybindings[0][b]);
1559 Con_Printf("\"%s\" is not bound\n", Cmd_Argv (1));
1562 // copy the rest of the command line
1563 cmd[0] = 0; // start out with a null string
1564 for (i = 2; i < c; i++) {
1565 strlcat (cmd, Cmd_Argv (i), sizeof (cmd));
1567 strlcat (cmd, " ", sizeof (cmd));
1570 if(!Key_SetBinding (b, 0, cmd))
1571 Con_Printf("Key_SetBinding failed for unknown reason\n");
1576 Writes lines containing "bind key value"
1580 Key_WriteBindings (qfile_t *f)
1583 char bindbuf[MAX_INPUTLINE];
1586 for (j = 0; j < MAX_BINDMAPS; j++)
1588 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
1590 p = keybindings[j][i];
1593 Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\", false); // don't need to escape $ because cvars are not expanded inside bind
1595 FS_Printf(f, "bind %s \"%s\"\n", Key_KeynumToString (i), bindbuf);
1597 FS_Printf(f, "in_bind %d %s \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
1613 // register our functions
1615 Cmd_AddCommand ("in_bind", Key_In_Bind_f, "binds a command to the specified key in the selected bindmap");
1616 Cmd_AddCommand ("in_unbind", Key_In_Unbind_f, "removes command on the specified key in the selected bindmap");
1617 Cmd_AddCommand ("in_bindlist", Key_In_BindList_f, "bindlist: displays bound keys for all bindmaps, or the given bindmap");
1618 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");
1620 Cmd_AddCommand ("bind", Key_Bind_f, "binds a command to the specified key in bindmap 0");
1621 Cmd_AddCommand ("unbind", Key_Unbind_f, "removes a command on the specified key in bindmap 0");
1622 Cmd_AddCommand ("bindlist", Key_BindList_f, "bindlist: displays bound keys for bindmap 0 bindmaps");
1623 Cmd_AddCommand ("unbindall", Key_Unbindall_f, "removes all commands from all keys in all bindmaps (leaving only shift-escape and escape)");
1625 Cmd_AddCommand ("history", Key_History_f, "prints the history of executed commands (history X prints the last X entries, history -c clears the whole history)");
1627 Cvar_RegisterVariable (&con_closeontoggleconsole);
1633 Key_History_Shutdown();
1636 const char *Key_GetBind (int key, int bindmap)
1639 if (key < 0 || key >= MAX_KEYS)
1641 if(bindmap >= MAX_BINDMAPS)
1645 bind = keybindings[bindmap][key];
1649 bind = keybindings[key_bmap][key];
1651 bind = keybindings[key_bmap2][key];
1656 void Key_FindKeysForCommand (const char *command, int *keys, int numkeys, int bindmap)
1662 for (j = 0;j < numkeys;j++)
1665 if(bindmap >= MAX_BINDMAPS)
1670 for (j = 0; j < MAX_KEYS; ++j)
1672 b = Key_GetBind(j, bindmap);
1675 if (!strcmp (b, command) )
1678 if (count == numkeys)
1684 qboolean CL_VM_InputEvent (qboolean down, int key, int ascii);
1688 Called by the system between frames for both key up and key down events
1689 Should NOT be called during an interrupt!
1692 static char tbl_keyascii[MAX_KEYS];
1693 static keydest_t tbl_keydest[MAX_KEYS];
1695 typedef struct eventqueueitem_s
1702 static int events_blocked = 0;
1703 static eventqueueitem_t eventqueue[32];
1704 static unsigned eventqueue_idx = 0;
1706 static void Key_EventQueue_Add(int key, int ascii, qboolean down)
1708 if(eventqueue_idx < sizeof(eventqueue) / sizeof(*eventqueue))
1710 eventqueue[eventqueue_idx].key = key;
1711 eventqueue[eventqueue_idx].ascii = ascii;
1712 eventqueue[eventqueue_idx].down = down;
1717 void Key_EventQueue_Block(void)
1719 // block key events until call to Unblock
1720 events_blocked = true;
1723 void Key_EventQueue_Unblock(void)
1725 // unblocks key events again
1727 events_blocked = false;
1728 for(i = 0; i < eventqueue_idx; ++i)
1729 Key_Event(eventqueue[i].key, eventqueue[i].ascii, eventqueue[i].down);
1734 Key_Event (int key, int ascii, qboolean down)
1738 keydest_t keydest = key_dest;
1740 if (key < 0 || key >= MAX_KEYS)
1745 Key_EventQueue_Add(key, ascii, down);
1749 if (ascii == 0x80 && utf8_enable.integer) // pressing AltGr-5 (or AltGr-e) and for some reason we get windows-1252 encoding?
1750 ascii = 0x20AC; // we want the Euro currency sign
1751 // TODO find out which vid_ drivers do it and fix it there
1752 // but catching U+0080 here is no loss as that char is not useful anyway
1755 bind = keybindings[key_bmap][key];
1757 bind = keybindings[key_bmap2][key];
1759 if (developer_insane.integer)
1760 Con_DPrintf("Key_Event(%i, '%c', %s) keydown %i bind \"%s\"\n", key, ascii ? ascii : '?', down ? "down" : "up", keydown[key], bind ? bind : "");
1762 if(key_consoleactive)
1763 keydest = key_console;
1767 // increment key repeat count each time a down is received so that things
1768 // which want to ignore key repeat can ignore it
1769 keydown[key] = min(keydown[key] + 1, 2);
1770 if(keydown[key] == 1) {
1771 tbl_keyascii[key] = ascii;
1772 tbl_keydest[key] = keydest;
1774 ascii = tbl_keyascii[key];
1775 keydest = tbl_keydest[key];
1780 // clear repeat count now that the key is released
1782 keydest = tbl_keydest[key];
1783 ascii = tbl_keyascii[key];
1786 if(keydest == key_void)
1789 // key_consoleactive is a flag not a key_dest because the console is a
1790 // high priority overlay ontop of the normal screen (designed as a safety
1791 // feature so that developers and users can rescue themselves from a bad
1794 // this also means that toggling the console on/off does not lose the old
1797 // specially handle escape (togglemenu) and shift-escape (toggleconsole)
1798 // engine bindings, these are not handled as normal binds so that the user
1799 // can recover from a completely empty bindmap
1800 if (key == K_ESCAPE)
1802 // ignore key repeats on escape
1803 if (keydown[key] > 1)
1806 // escape does these things:
1807 // key_consoleactive - close console
1808 // key_message - abort messagemode
1809 // key_menu - go to parent menu (or key_game)
1810 // key_game - open menu
1812 // in all modes shift-escape toggles console
1813 if (keydown[K_SHIFT])
1817 Con_ToggleConsole_f ();
1818 tbl_keydest[key] = key_void; // esc release should go nowhere (especially not to key_menu or key_game)
1828 if(key_consoleactive & KEY_CONSOLEACTIVE_FORCED)
1830 key_consoleactive &= ~KEY_CONSOLEACTIVE_USER;
1834 Con_ToggleConsole_f();
1840 Key_Message (key, ascii); // that'll close the message input
1844 case key_menu_grabbed:
1845 MR_KeyEvent (key, ascii, down);
1849 // csqc has priority over toggle menu if it wants to (e.g. handling escape for UI stuff in-game.. :sick:)
1850 q = CL_VM_InputEvent(down, key, ascii);
1856 Con_Printf ("Key_Event: Bad key_dest\n");
1861 // send function keydowns to interpreter no matter what mode is (unless the menu has specifically grabbed the keyboard, for rebinding keys)
1862 // VorteX: Omnicide does bind F* keys
1863 if (keydest != key_menu_grabbed)
1864 if (key >= K_F1 && key <= K_F12 && gamemode != GAME_BLOODOMNICIDE)
1868 if(keydown[key] == 1 && down)
1870 // button commands add keynum as a parm
1872 Cbuf_AddText (va("%s %i\n", bind, key));
1875 Cbuf_AddText (bind);
1876 Cbuf_AddText ("\n");
1878 } else if(bind[0] == '+' && !down && keydown[key] == 0)
1879 Cbuf_AddText(va("-%s %i\n", bind + 1, key));
1884 // send input to console if it wants it
1885 if (keydest == key_console)
1889 // con_closeontoggleconsole enables toggleconsole keys to close the
1890 // console, as long as they are not the color prefix character
1891 // (special exemption for german keyboard layouts)
1892 if (con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && (key_consoleactive & KEY_CONSOLEACTIVE_USER) && (con_closeontoggleconsole.integer >= ((ascii != STRING_COLOR_TAG) ? 2 : 3) || key_linepos == 1))
1894 Con_ToggleConsole_f ();
1897 Key_Console (key, ascii);
1901 // handle toggleconsole in menu too
1902 if (keydest == key_menu)
1904 if (down && con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && ascii != STRING_COLOR_TAG)
1906 Con_ToggleConsole_f ();
1907 tbl_keydest[key] = key_void; // key release should go nowhere (especially not to key_menu or key_game)
1912 // ignore binds while a video is played, let the video system handle the key event
1913 if (cl_videoplaying)
1915 if (gamemode == GAME_BLOODOMNICIDE) // menu controls key events
1916 MR_KeyEvent(key, ascii, down);
1918 CL_Video_KeyEvent (key, ascii, keydown[key] != 0);
1922 // anything else is a key press into the game, chat line, or menu
1927 Key_Message (key, ascii);
1930 case key_menu_grabbed:
1931 MR_KeyEvent (key, ascii, down);
1934 q = CL_VM_InputEvent(down, key, ascii);
1935 // ignore key repeats on binds and only send the bind if the event hasnt been already processed by csqc
1938 if(keydown[key] == 1 && down)
1940 // button commands add keynum as a parm
1942 Cbuf_AddText (va("%s %i\n", bind, key));
1945 Cbuf_AddText (bind);
1946 Cbuf_AddText ("\n");
1948 } else if(bind[0] == '+' && !down && keydown[key] == 0)
1949 Cbuf_AddText(va("-%s %i\n", bind + 1, key));
1953 Con_Printf ("Key_Event: Bad key_dest\n");
1963 Key_ClearStates (void)
1965 memset(keydown, 0, sizeof(keydown));