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 {"JOY_UP", K_JOY_UP},
502 {"JOY_DOWN", K_JOY_DOWN},
503 {"JOY_LEFT", K_JOY_LEFT},
504 {"JOY_RIGHT", K_JOY_RIGHT},
506 {"SEMICOLON", ';'}, // because a raw semicolon separates commands
510 {"APOSTROPHE", '\''},
511 {"BACKSLASH", '\\'}, // because a raw backslash is used for special characters
513 {"MIDINOTE0", K_MIDINOTE0},
514 {"MIDINOTE1", K_MIDINOTE1},
515 {"MIDINOTE2", K_MIDINOTE2},
516 {"MIDINOTE3", K_MIDINOTE3},
517 {"MIDINOTE4", K_MIDINOTE4},
518 {"MIDINOTE5", K_MIDINOTE5},
519 {"MIDINOTE6", K_MIDINOTE6},
520 {"MIDINOTE7", K_MIDINOTE7},
521 {"MIDINOTE8", K_MIDINOTE8},
522 {"MIDINOTE9", K_MIDINOTE9},
523 {"MIDINOTE10", K_MIDINOTE10},
524 {"MIDINOTE11", K_MIDINOTE11},
525 {"MIDINOTE12", K_MIDINOTE12},
526 {"MIDINOTE13", K_MIDINOTE13},
527 {"MIDINOTE14", K_MIDINOTE14},
528 {"MIDINOTE15", K_MIDINOTE15},
529 {"MIDINOTE16", K_MIDINOTE16},
530 {"MIDINOTE17", K_MIDINOTE17},
531 {"MIDINOTE18", K_MIDINOTE18},
532 {"MIDINOTE19", K_MIDINOTE19},
533 {"MIDINOTE20", K_MIDINOTE20},
534 {"MIDINOTE21", K_MIDINOTE21},
535 {"MIDINOTE22", K_MIDINOTE22},
536 {"MIDINOTE23", K_MIDINOTE23},
537 {"MIDINOTE24", K_MIDINOTE24},
538 {"MIDINOTE25", K_MIDINOTE25},
539 {"MIDINOTE26", K_MIDINOTE26},
540 {"MIDINOTE27", K_MIDINOTE27},
541 {"MIDINOTE28", K_MIDINOTE28},
542 {"MIDINOTE29", K_MIDINOTE29},
543 {"MIDINOTE30", K_MIDINOTE30},
544 {"MIDINOTE31", K_MIDINOTE31},
545 {"MIDINOTE32", K_MIDINOTE32},
546 {"MIDINOTE33", K_MIDINOTE33},
547 {"MIDINOTE34", K_MIDINOTE34},
548 {"MIDINOTE35", K_MIDINOTE35},
549 {"MIDINOTE36", K_MIDINOTE36},
550 {"MIDINOTE37", K_MIDINOTE37},
551 {"MIDINOTE38", K_MIDINOTE38},
552 {"MIDINOTE39", K_MIDINOTE39},
553 {"MIDINOTE40", K_MIDINOTE40},
554 {"MIDINOTE41", K_MIDINOTE41},
555 {"MIDINOTE42", K_MIDINOTE42},
556 {"MIDINOTE43", K_MIDINOTE43},
557 {"MIDINOTE44", K_MIDINOTE44},
558 {"MIDINOTE45", K_MIDINOTE45},
559 {"MIDINOTE46", K_MIDINOTE46},
560 {"MIDINOTE47", K_MIDINOTE47},
561 {"MIDINOTE48", K_MIDINOTE48},
562 {"MIDINOTE49", K_MIDINOTE49},
563 {"MIDINOTE50", K_MIDINOTE50},
564 {"MIDINOTE51", K_MIDINOTE51},
565 {"MIDINOTE52", K_MIDINOTE52},
566 {"MIDINOTE53", K_MIDINOTE53},
567 {"MIDINOTE54", K_MIDINOTE54},
568 {"MIDINOTE55", K_MIDINOTE55},
569 {"MIDINOTE56", K_MIDINOTE56},
570 {"MIDINOTE57", K_MIDINOTE57},
571 {"MIDINOTE58", K_MIDINOTE58},
572 {"MIDINOTE59", K_MIDINOTE59},
573 {"MIDINOTE60", K_MIDINOTE60},
574 {"MIDINOTE61", K_MIDINOTE61},
575 {"MIDINOTE62", K_MIDINOTE62},
576 {"MIDINOTE63", K_MIDINOTE63},
577 {"MIDINOTE64", K_MIDINOTE64},
578 {"MIDINOTE65", K_MIDINOTE65},
579 {"MIDINOTE66", K_MIDINOTE66},
580 {"MIDINOTE67", K_MIDINOTE67},
581 {"MIDINOTE68", K_MIDINOTE68},
582 {"MIDINOTE69", K_MIDINOTE69},
583 {"MIDINOTE70", K_MIDINOTE70},
584 {"MIDINOTE71", K_MIDINOTE71},
585 {"MIDINOTE72", K_MIDINOTE72},
586 {"MIDINOTE73", K_MIDINOTE73},
587 {"MIDINOTE74", K_MIDINOTE74},
588 {"MIDINOTE75", K_MIDINOTE75},
589 {"MIDINOTE76", K_MIDINOTE76},
590 {"MIDINOTE77", K_MIDINOTE77},
591 {"MIDINOTE78", K_MIDINOTE78},
592 {"MIDINOTE79", K_MIDINOTE79},
593 {"MIDINOTE80", K_MIDINOTE80},
594 {"MIDINOTE81", K_MIDINOTE81},
595 {"MIDINOTE82", K_MIDINOTE82},
596 {"MIDINOTE83", K_MIDINOTE83},
597 {"MIDINOTE84", K_MIDINOTE84},
598 {"MIDINOTE85", K_MIDINOTE85},
599 {"MIDINOTE86", K_MIDINOTE86},
600 {"MIDINOTE87", K_MIDINOTE87},
601 {"MIDINOTE88", K_MIDINOTE88},
602 {"MIDINOTE89", K_MIDINOTE89},
603 {"MIDINOTE90", K_MIDINOTE90},
604 {"MIDINOTE91", K_MIDINOTE91},
605 {"MIDINOTE92", K_MIDINOTE92},
606 {"MIDINOTE93", K_MIDINOTE93},
607 {"MIDINOTE94", K_MIDINOTE94},
608 {"MIDINOTE95", K_MIDINOTE95},
609 {"MIDINOTE96", K_MIDINOTE96},
610 {"MIDINOTE97", K_MIDINOTE97},
611 {"MIDINOTE98", K_MIDINOTE98},
612 {"MIDINOTE99", K_MIDINOTE99},
613 {"MIDINOTE100", K_MIDINOTE100},
614 {"MIDINOTE101", K_MIDINOTE101},
615 {"MIDINOTE102", K_MIDINOTE102},
616 {"MIDINOTE103", K_MIDINOTE103},
617 {"MIDINOTE104", K_MIDINOTE104},
618 {"MIDINOTE105", K_MIDINOTE105},
619 {"MIDINOTE106", K_MIDINOTE106},
620 {"MIDINOTE107", K_MIDINOTE107},
621 {"MIDINOTE108", K_MIDINOTE108},
622 {"MIDINOTE109", K_MIDINOTE109},
623 {"MIDINOTE110", K_MIDINOTE110},
624 {"MIDINOTE111", K_MIDINOTE111},
625 {"MIDINOTE112", K_MIDINOTE112},
626 {"MIDINOTE113", K_MIDINOTE113},
627 {"MIDINOTE114", K_MIDINOTE114},
628 {"MIDINOTE115", K_MIDINOTE115},
629 {"MIDINOTE116", K_MIDINOTE116},
630 {"MIDINOTE117", K_MIDINOTE117},
631 {"MIDINOTE118", K_MIDINOTE118},
632 {"MIDINOTE119", K_MIDINOTE119},
633 {"MIDINOTE120", K_MIDINOTE120},
634 {"MIDINOTE121", K_MIDINOTE121},
635 {"MIDINOTE122", K_MIDINOTE122},
636 {"MIDINOTE123", K_MIDINOTE123},
637 {"MIDINOTE124", K_MIDINOTE124},
638 {"MIDINOTE125", K_MIDINOTE125},
639 {"MIDINOTE126", K_MIDINOTE126},
640 {"MIDINOTE127", K_MIDINOTE127},
646 ==============================================================================
648 LINE TYPING INTO THE CONSOLE
650 ==============================================================================
654 Key_ClearEditLine (int edit_line)
656 memset (key_line, '\0', sizeof(key_line));
663 Interactive line editing and console scrollback
667 Key_Console (int key, int unicode)
669 // LordHavoc: copied most of this from Q2 to improve keyboard handling
696 case K_KP_RIGHTARROW:
716 if ((key == 'v' && keydown[K_CTRL]) || ((key == K_INS || key == K_KP_INS) && keydown[K_SHIFT]))
719 if ((cbd = Sys_GetClipboardData()) != 0)
726 if (*p == '\r' && *(p+1) == '\n')
731 else if (*p == '\n' || *p == '\r' || *p == '\b')
736 strtok(cbd, "\n\r\b");
738 i = (int)strlen(cbd);
739 if (i + key_linepos >= MAX_INPUTLINE)
740 i= MAX_INPUTLINE - key_linepos - 1;
743 // terencehill: insert the clipboard text between the characters of the line
745 char *temp = (char *) Z_Malloc(MAX_INPUTLINE);
748 if ( key_linepos < (int)strlen(key_line) )
749 strlcpy(temp, key_line + key_linepos, (int)strlen(key_line) - key_linepos +1);
750 key_line[key_linepos] = 0;
751 strlcat(key_line, cbd, sizeof(key_line));
753 strlcat(key_line, temp, sizeof(key_line));
757 // blub: I'm changing this to use memmove() like the rest of the code does.
759 memmove(key_line + key_linepos + i, key_line + key_linepos, sizeof(key_line) - key_linepos - i);
760 memcpy(key_line + key_linepos, cbd, i);
768 if (key == 'l' && keydown[K_CTRL])
770 Cbuf_AddText ("clear\n");
774 if (key == 'u' && keydown[K_CTRL]) // like vi/readline ^u: delete currently edited line
783 if (key == 'q' && keydown[K_CTRL]) // like zsh ^q: push line to history, don't execute, and clear
793 if (key == K_ENTER || key == K_KP_ENTER)
795 Cbuf_AddText (key_line+1); // skip the ]
799 key_line[1] = 0; // EvilTypeGuy: null terminate
801 // force an update, because the command may take some time
802 if (cls.state == ca_disconnected)
809 if(keydown[K_CTRL]) // append to the cvar its value
811 int cvar_len, cvar_str_len, chars_to_move;
813 char cvar[MAX_INPUTLINE];
814 const char *cvar_str;
816 // go to the start of the variable
819 k = key_line[key_linepos];
820 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
825 // save the variable name in cvar
826 for(cvar_len=0; (k = key_line[key_linepos + cvar_len]) != 0; cvar_len++)
828 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
836 // go to the end of the cvar
837 key_linepos += cvar_len;
839 // save the content of the variable in cvar_str
840 cvar_str = Cvar_VariableString(cvar);
841 cvar_str_len = strlen(cvar_str);
845 // insert space and cvar_str in key_line
846 chars_to_move = strlen(&key_line[key_linepos]);
847 if (key_linepos + 1 + cvar_str_len + chars_to_move < MAX_INPUTLINE)
850 memmove(&key_line[key_linepos + 1 + cvar_str_len], &key_line[key_linepos], chars_to_move);
851 key_line[key_linepos++] = ' ';
852 memcpy(&key_line[key_linepos], cvar_str, cvar_str_len);
853 key_linepos += cvar_str_len;
854 key_line[key_linepos + chars_to_move] = 0;
857 Con_Printf("Couldn't append cvar value, edit line too long.\n");
860 // Enhanced command completion
861 // by EvilTypeGuy eviltypeguy@qeradiant.com
862 // Thanks to Fett, Taniwha
863 Con_CompleteCommandLine();
867 // Advanced Console Editing by Radix radix@planetquake.com
868 // Added/Modified by EvilTypeGuy eviltypeguy@qeradiant.com
870 // Enhanced by terencehill
872 // move cursor to the previous character
873 if (key == K_LEFTARROW || key == K_KP_LEFTARROW)
877 if(keydown[K_CTRL]) // move cursor to the previous word
883 if(pos) // skip all "; ' after the word
887 if (!(k == '\"' || k == ';' || k == ' ' || k == '\''))
895 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
898 key_linepos = pos + 1;
900 else if(keydown[K_SHIFT]) // move cursor to the previous character ignoring colors
904 pos = u8_prevbyte(key_line+1, key_linepos-1) + 1; // do NOT give the ']' to u8_prevbyte
906 if(pos-1 > 0 && key_line[pos-1] == STRING_COLOR_TAG && isdigit(key_line[pos]))
908 else if(pos-4 > 0 && key_line[pos-4] == STRING_COLOR_TAG && key_line[pos-3] == STRING_COLOR_RGB_TAG_CHAR
909 && isxdigit(key_line[pos-2]) && isxdigit(key_line[pos-1]) && isxdigit(key_line[pos]))
913 if(pos-1 > 0 && key_line[pos-1] == STRING_COLOR_TAG && key_line[pos] == STRING_COLOR_TAG) // consider ^^ as a character
918 // we need to move to the beginning of the character when in a wide character:
919 u8_charidx(key_line, pos + 1, &inchar);
920 key_linepos = pos + 1 - inchar;
924 key_linepos = u8_prevbyte(key_line+1, key_linepos-1) + 1; // do NOT give the ']' to u8_prevbyte
929 // delete char before cursor
930 if (key == K_BACKSPACE || (key == 'h' && keydown[K_CTRL]))
934 int newpos = u8_prevbyte(key_line+1, key_linepos-1) + 1; // do NOT give the ']' to u8_prevbyte
935 strlcpy(key_line + newpos, key_line + key_linepos, sizeof(key_line) + 1 - key_linepos);
936 key_linepos = newpos;
941 // delete char on cursor
942 if (key == K_DEL || key == K_KP_DEL)
945 linelen = strlen(key_line);
946 if (key_linepos < (int)linelen)
947 memmove(key_line + key_linepos, key_line + key_linepos + u8_bytelen(key_line + key_linepos, 1), linelen - key_linepos);
952 // move cursor to the next character
953 if (key == K_RIGHTARROW || key == K_KP_RIGHTARROW)
955 if (key_linepos >= (int)strlen(key_line))
957 if(keydown[K_CTRL]) // move cursor to the next word
961 len = (int)strlen(key_line);
967 if(k == '\"' || k == ';' || k == ' ' || k == '\'')
971 if (pos < len) // skip all "; ' after the word
975 if (!(k == '\"' || k == ';' || k == ' ' || k == '\''))
980 else if(keydown[K_SHIFT]) // move cursor to the next character ignoring colors
983 len = (int)strlen(key_line);
986 // go beyond all initial consecutive color tags, if any
988 while (key_line[pos] == STRING_COLOR_TAG)
990 if(isdigit(key_line[pos+1]))
992 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]))
999 if (key_line[pos] == STRING_COLOR_TAG && key_line[pos+1] == STRING_COLOR_TAG) // consider ^^ as a character
1001 pos += u8_bytelen(key_line + pos, 1);
1003 // now go beyond all next consecutive color tags, if any
1005 while (key_line[pos] == STRING_COLOR_TAG)
1007 if(isdigit(key_line[pos+1]))
1009 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]))
1017 key_linepos += u8_bytelen(key_line + key_linepos, 1);
1021 if (key == K_INS || key == K_KP_INS) // toggle insert mode
1027 // End Advanced Console Editing
1029 if (key == K_UPARROW || key == K_KP_UPARROW || (key == 'p' && keydown[K_CTRL]))
1035 if (key == K_DOWNARROW || key == K_KP_DOWNARROW || (key == 'n' && keydown[K_CTRL]))
1040 // ~1.0795 = 82/76 using con_textsize 64 76 is height of the char, 6 is the distance between 2 lines
1042 if (keydown[K_CTRL])
1044 // prints all the matching commands
1047 Key_History_Find_All();
1050 // Search forwards/backwards, pointing the history's index to the
1051 // matching command but without fetching it to let one continue the search.
1052 // To fetch it, it suffices to just press UP or DOWN.
1055 if (keydown[K_SHIFT])
1056 Key_History_Find_Forwards();
1058 Key_History_Find_Backwards();
1061 // go to the last/first command of the history
1064 Key_History_First();
1074 if (key == K_PGUP || key == K_KP_PGUP)
1078 con_backscroll += ((vid_conheight.integer >> 2) / con_textsize.integer)-1;
1081 con_backscroll += ((vid_conheight.integer >> 1) / con_textsize.integer)-3;
1085 if (key == K_PGDN || key == K_KP_PGDN)
1089 con_backscroll -= ((vid_conheight.integer >> 2) / con_textsize.integer)-1;
1092 con_backscroll -= ((vid_conheight.integer >> 1) / con_textsize.integer)-3;
1096 if (key == K_MWHEELUP)
1099 con_backscroll += 1;
1100 else if(keydown[K_SHIFT])
1101 con_backscroll += ((vid_conheight.integer >> 2) / con_textsize.integer)-1;
1103 con_backscroll += 5;
1107 if (key == K_MWHEELDOWN)
1110 con_backscroll -= 1;
1111 else if(keydown[K_SHIFT])
1112 con_backscroll -= ((vid_conheight.integer >> 2) / con_textsize.integer)-1;
1114 con_backscroll -= 5;
1118 if (keydown[K_CTRL])
1121 if (key == '+' || key == K_KP_PLUS)
1123 if (con_textsize.integer < 128)
1124 Cvar_SetValueQuick(&con_textsize, con_textsize.integer + 1);
1128 if (key == '-' || key == K_KP_MINUS)
1130 if (con_textsize.integer > 1)
1131 Cvar_SetValueQuick(&con_textsize, con_textsize.integer - 1);
1135 if (key == '0' || key == K_KP_INS)
1137 Cvar_SetValueQuick(&con_textsize, atoi(Cvar_VariableDefString("con_textsize")));
1142 if (key == K_HOME || key == K_KP_HOME)
1144 if (keydown[K_CTRL])
1145 con_backscroll = CON_TEXTSIZE;
1151 if (key == K_END || key == K_KP_END)
1153 if (keydown[K_CTRL])
1156 key_linepos = (int)strlen(key_line);
1164 if (key_linepos < MAX_INPUTLINE-1)
1169 blen = u8_fromchar(unicode, buf, sizeof(buf));
1172 len = (int)strlen(&key_line[key_linepos]);
1173 // check insert mode, or always insert if at end of line
1174 if (key_insert || len == 0)
1176 // can't use strcpy to move string to right
1178 //memmove(&key_line[key_linepos + u8_bytelen(key_line + key_linepos, 1)], &key_line[key_linepos], len);
1179 memmove(&key_line[key_linepos + blen], &key_line[key_linepos], len);
1181 memcpy(key_line + key_linepos, buf, blen);
1182 key_linepos += blen;
1183 //key_linepos += u8_fromchar(unicode, key_line + key_linepos, sizeof(key_line) - key_linepos - 1);
1184 //key_line[key_linepos] = ascii;
1189 //============================================================================
1192 char chat_buffer[MAX_INPUTLINE];
1193 unsigned int chat_bufferlen = 0;
1195 extern int Nicks_CompleteChatLine(char *buffer, size_t size, unsigned int pos);
1198 Key_Message (int key, int ascii)
1200 if (key == K_ENTER || ascii == 10 || ascii == 13)
1203 Cmd_ExecuteString(chat_buffer, src_command); // not Cbuf_AddText to allow semiclons in args; however, this allows no variables then. Use aliases!
1205 Cmd_ForwardStringToServer(va("%s %s", chat_mode ? "say_team" : "say ", chat_buffer));
1207 key_dest = key_game;
1213 // TODO add support for arrow keys and simple editing
1215 if (key == K_ESCAPE) {
1216 key_dest = key_game;
1222 if (key == K_BACKSPACE) {
1223 if (chat_bufferlen) {
1224 chat_bufferlen = u8_prevbyte(chat_buffer, chat_bufferlen);
1225 chat_buffer[chat_bufferlen] = 0;
1231 chat_bufferlen = Nicks_CompleteChatLine(chat_buffer, sizeof(chat_buffer), chat_bufferlen);
1235 // ctrl+key generates an ascii value < 32 and shows a char from the charmap
1236 if (ascii > 0 && ascii < 32 && utf8_enable.integer)
1237 ascii = 0xE000 + ascii;
1239 if (chat_bufferlen == sizeof (chat_buffer) - 1)
1243 return; // non printable
1245 chat_bufferlen += u8_fromchar(ascii, chat_buffer+chat_bufferlen, sizeof(chat_buffer) - chat_bufferlen - 1);
1247 //chat_buffer[chat_bufferlen++] = ascii;
1248 //chat_buffer[chat_bufferlen] = 0;
1251 //============================================================================
1256 Returns a key number to be used to index keybindings[] by looking at
1257 the given string. Single ascii characters return themselves, while
1258 the K_* names are matched up.
1262 Key_StringToKeynum (const char *str)
1264 const keyname_t *kn;
1266 if (!str || !str[0])
1269 return tolower(str[0]);
1271 for (kn = keynames; kn->name; kn++) {
1272 if (!strcasecmp (str, kn->name))
1280 Returns a string (either a single ascii char, or a K_* name) for the
1282 FIXME: handle quote special (general escape sequence?)
1286 Key_KeynumToString (int keynum)
1288 const keyname_t *kn;
1289 static char tinystr[2];
1291 // -1 is an invalid code
1293 return "<KEY NOT FOUND>";
1295 // search overrides first, because some characters are special
1296 for (kn = keynames; kn->name; kn++)
1297 if (keynum == kn->keynum)
1300 // if it is printable, output it as a single character
1301 if (keynum > 32 && keynum < 256)
1303 tinystr[0] = keynum;
1308 // if it is not overridden and not printable, we don't know what to do with it
1309 return "<UNKNOWN KEYNUM>";
1314 Key_SetBinding (int keynum, int bindmap, const char *binding)
1319 if (keynum == -1 || keynum >= MAX_KEYS)
1321 if ((bindmap < 0) || (bindmap >= MAX_BINDMAPS))
1324 // free old bindings
1325 if (keybindings[bindmap][keynum]) {
1326 Z_Free (keybindings[bindmap][keynum]);
1327 keybindings[bindmap][keynum] = NULL;
1329 if(!binding[0]) // make "" binds be removed --blub
1331 // allocate memory for new binding
1332 l = strlen (binding);
1333 newbinding = (char *)Z_Malloc (l + 1);
1334 memcpy (newbinding, binding, l + 1);
1336 keybindings[bindmap][keynum] = newbinding;
1340 void Key_GetBindMap(int *fg, int *bg)
1348 qboolean Key_SetBindMap(int fg, int bg)
1350 if(fg >= MAX_BINDMAPS)
1352 if(bg >= MAX_BINDMAPS)
1362 Key_In_Unbind_f (void)
1365 char *errchar = NULL;
1367 if (Cmd_Argc () != 3) {
1368 Con_Print("in_unbind <bindmap> <key> : remove commands from a key\n");
1372 m = strtol(Cmd_Argv (1), &errchar, 0);
1373 if ((m < 0) || (m >= MAX_BINDMAPS) || (errchar && *errchar)) {
1374 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
1378 b = Key_StringToKeynum (Cmd_Argv (2));
1380 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (2));
1384 if(!Key_SetBinding (b, m, ""))
1385 Con_Printf("Key_SetBinding failed for unknown reason\n");
1389 Key_In_Bind_f (void)
1392 char cmd[MAX_INPUTLINE];
1393 char *errchar = NULL;
1397 if (c != 3 && c != 4) {
1398 Con_Print("in_bind <bindmap> <key> [command] : attach a command to a key\n");
1402 m = strtol(Cmd_Argv (1), &errchar, 0);
1403 if ((m < 0) || (m >= MAX_BINDMAPS) || (errchar && *errchar)) {
1404 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
1408 b = Key_StringToKeynum (Cmd_Argv (2));
1409 if (b == -1 || b >= MAX_KEYS) {
1410 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (2));
1415 if (keybindings[m][b])
1416 Con_Printf("\"%s\" = \"%s\"\n", Cmd_Argv (2), keybindings[m][b]);
1418 Con_Printf("\"%s\" is not bound\n", Cmd_Argv (2));
1421 // copy the rest of the command line
1422 cmd[0] = 0; // start out with a null string
1423 for (i = 3; i < c; i++) {
1424 strlcat (cmd, Cmd_Argv (i), sizeof (cmd));
1426 strlcat (cmd, " ", sizeof (cmd));
1429 if(!Key_SetBinding (b, m, cmd))
1430 Con_Printf("Key_SetBinding failed for unknown reason\n");
1434 Key_In_Bindmap_f (void)
1437 char *errchar = NULL;
1442 Con_Print("in_bindmap <bindmap> <fallback>: set current bindmap and fallback\n");
1446 m1 = strtol(Cmd_Argv (1), &errchar, 0);
1447 if ((m1 < 0) || (m1 >= MAX_BINDMAPS) || (errchar && *errchar)) {
1448 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
1452 m2 = strtol(Cmd_Argv (2), &errchar, 0);
1453 if ((m2 < 0) || (m2 >= MAX_BINDMAPS) || (errchar && *errchar)) {
1454 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(2));
1467 if (Cmd_Argc () != 2) {
1468 Con_Print("unbind <key> : remove commands from a key\n");
1472 b = Key_StringToKeynum (Cmd_Argv (1));
1474 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (1));
1478 if(!Key_SetBinding (b, 0, ""))
1479 Con_Printf("Key_SetBinding failed for unknown reason\n");
1483 Key_Unbindall_f (void)
1487 for (j = 0; j < MAX_BINDMAPS; j++)
1488 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
1489 if (keybindings[j][i])
1490 Key_SetBinding (i, j, "");
1494 Key_PrintBindList(int j)
1496 char bindbuf[MAX_INPUTLINE];
1500 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
1502 p = keybindings[j][i];
1505 Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\", false);
1507 Con_Printf("^2%s ^7= \"%s\"\n", Key_KeynumToString (i), bindbuf);
1509 Con_Printf("^3bindmap %d: ^2%s ^7= \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
1515 Key_In_BindList_f (void)
1518 char *errchar = NULL;
1522 m = strtol(Cmd_Argv(1), &errchar, 0);
1523 if ((m < 0) || (m >= MAX_BINDMAPS) || (errchar && *errchar)) {
1524 Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
1527 Key_PrintBindList(m);
1531 for (m = 0; m < MAX_BINDMAPS; m++)
1532 Key_PrintBindList(m);
1537 Key_BindList_f (void)
1539 Key_PrintBindList(0);
1546 char cmd[MAX_INPUTLINE];
1550 if (c != 2 && c != 3) {
1551 Con_Print("bind <key> [command] : attach a command to a key\n");
1554 b = Key_StringToKeynum (Cmd_Argv (1));
1555 if (b == -1 || b >= MAX_KEYS) {
1556 Con_Printf("\"%s\" isn't a valid key\n", Cmd_Argv (1));
1561 if (keybindings[0][b])
1562 Con_Printf("\"%s\" = \"%s\"\n", Cmd_Argv (1), keybindings[0][b]);
1564 Con_Printf("\"%s\" is not bound\n", Cmd_Argv (1));
1567 // copy the rest of the command line
1568 cmd[0] = 0; // start out with a null string
1569 for (i = 2; i < c; i++) {
1570 strlcat (cmd, Cmd_Argv (i), sizeof (cmd));
1572 strlcat (cmd, " ", sizeof (cmd));
1575 if(!Key_SetBinding (b, 0, cmd))
1576 Con_Printf("Key_SetBinding failed for unknown reason\n");
1581 Writes lines containing "bind key value"
1585 Key_WriteBindings (qfile_t *f)
1588 char bindbuf[MAX_INPUTLINE];
1591 for (j = 0; j < MAX_BINDMAPS; j++)
1593 for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
1595 p = keybindings[j][i];
1598 Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\", false); // don't need to escape $ because cvars are not expanded inside bind
1600 FS_Printf(f, "bind %s \"%s\"\n", Key_KeynumToString (i), bindbuf);
1602 FS_Printf(f, "in_bind %d %s \"%s\"\n", j, Key_KeynumToString (i), bindbuf);
1618 // register our functions
1620 Cmd_AddCommand ("in_bind", Key_In_Bind_f, "binds a command to the specified key in the selected bindmap");
1621 Cmd_AddCommand ("in_unbind", Key_In_Unbind_f, "removes command on the specified key in the selected bindmap");
1622 Cmd_AddCommand ("in_bindlist", Key_In_BindList_f, "bindlist: displays bound keys for all bindmaps, or the given bindmap");
1623 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");
1625 Cmd_AddCommand ("bind", Key_Bind_f, "binds a command to the specified key in bindmap 0");
1626 Cmd_AddCommand ("unbind", Key_Unbind_f, "removes a command on the specified key in bindmap 0");
1627 Cmd_AddCommand ("bindlist", Key_BindList_f, "bindlist: displays bound keys for bindmap 0 bindmaps");
1628 Cmd_AddCommand ("unbindall", Key_Unbindall_f, "removes all commands from all keys in all bindmaps (leaving only shift-escape and escape)");
1630 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)");
1632 Cvar_RegisterVariable (&con_closeontoggleconsole);
1638 Key_History_Shutdown();
1641 const char *Key_GetBind (int key, int bindmap)
1644 if (key < 0 || key >= MAX_KEYS)
1646 if(bindmap >= MAX_BINDMAPS)
1650 bind = keybindings[bindmap][key];
1654 bind = keybindings[key_bmap][key];
1656 bind = keybindings[key_bmap2][key];
1661 void Key_FindKeysForCommand (const char *command, int *keys, int numkeys, int bindmap)
1667 for (j = 0;j < numkeys;j++)
1670 if(bindmap >= MAX_BINDMAPS)
1675 for (j = 0; j < MAX_KEYS; ++j)
1677 b = Key_GetBind(j, bindmap);
1680 if (!strcmp (b, command) )
1683 if (count == numkeys)
1689 qboolean CL_VM_InputEvent (qboolean down, int key, int ascii);
1693 Called by the system between frames for both key up and key down events
1694 Should NOT be called during an interrupt!
1697 static char tbl_keyascii[MAX_KEYS];
1698 static keydest_t tbl_keydest[MAX_KEYS];
1700 typedef struct eventqueueitem_s
1707 static int events_blocked = 0;
1708 static eventqueueitem_t eventqueue[32];
1709 static unsigned eventqueue_idx = 0;
1711 static void Key_EventQueue_Add(int key, int ascii, qboolean down)
1713 if(eventqueue_idx < sizeof(eventqueue) / sizeof(*eventqueue))
1715 eventqueue[eventqueue_idx].key = key;
1716 eventqueue[eventqueue_idx].ascii = ascii;
1717 eventqueue[eventqueue_idx].down = down;
1722 void Key_EventQueue_Block(void)
1724 // block key events until call to Unblock
1725 events_blocked = true;
1728 void Key_EventQueue_Unblock(void)
1730 // unblocks key events again
1732 events_blocked = false;
1733 for(i = 0; i < eventqueue_idx; ++i)
1734 Key_Event(eventqueue[i].key, eventqueue[i].ascii, eventqueue[i].down);
1739 Key_Event (int key, int ascii, qboolean down)
1743 keydest_t keydest = key_dest;
1745 if (key < 0 || key >= MAX_KEYS)
1750 Key_EventQueue_Add(key, ascii, down);
1754 if (ascii == 0x80 && utf8_enable.integer) // pressing AltGr-5 (or AltGr-e) and for some reason we get windows-1252 encoding?
1755 ascii = 0x20AC; // we want the Euro currency sign
1756 // TODO find out which vid_ drivers do it and fix it there
1757 // but catching U+0080 here is no loss as that char is not useful anyway
1760 bind = keybindings[key_bmap][key];
1762 bind = keybindings[key_bmap2][key];
1764 if (developer_insane.integer)
1765 Con_DPrintf("Key_Event(%i, '%c', %s) keydown %i bind \"%s\"\n", key, ascii ? ascii : '?', down ? "down" : "up", keydown[key], bind ? bind : "");
1767 if(key_consoleactive)
1768 keydest = key_console;
1772 // increment key repeat count each time a down is received so that things
1773 // which want to ignore key repeat can ignore it
1774 keydown[key] = min(keydown[key] + 1, 2);
1775 if(keydown[key] == 1) {
1776 tbl_keyascii[key] = ascii;
1777 tbl_keydest[key] = keydest;
1779 ascii = tbl_keyascii[key];
1780 keydest = tbl_keydest[key];
1785 // clear repeat count now that the key is released
1787 keydest = tbl_keydest[key];
1788 ascii = tbl_keyascii[key];
1791 if(keydest == key_void)
1794 // key_consoleactive is a flag not a key_dest because the console is a
1795 // high priority overlay ontop of the normal screen (designed as a safety
1796 // feature so that developers and users can rescue themselves from a bad
1799 // this also means that toggling the console on/off does not lose the old
1802 // specially handle escape (togglemenu) and shift-escape (toggleconsole)
1803 // engine bindings, these are not handled as normal binds so that the user
1804 // can recover from a completely empty bindmap
1805 if (key == K_ESCAPE)
1807 // ignore key repeats on escape
1808 if (keydown[key] > 1)
1811 // escape does these things:
1812 // key_consoleactive - close console
1813 // key_message - abort messagemode
1814 // key_menu - go to parent menu (or key_game)
1815 // key_game - open menu
1817 // in all modes shift-escape toggles console
1818 if (keydown[K_SHIFT])
1822 Con_ToggleConsole_f ();
1823 tbl_keydest[key] = key_void; // esc release should go nowhere (especially not to key_menu or key_game)
1833 if(key_consoleactive & KEY_CONSOLEACTIVE_FORCED)
1835 key_consoleactive &= ~KEY_CONSOLEACTIVE_USER;
1839 Con_ToggleConsole_f();
1845 Key_Message (key, ascii); // that'll close the message input
1849 case key_menu_grabbed:
1850 MR_KeyEvent (key, ascii, down);
1854 // csqc has priority over toggle menu if it wants to (e.g. handling escape for UI stuff in-game.. :sick:)
1855 q = CL_VM_InputEvent(down, key, ascii);
1861 Con_Printf ("Key_Event: Bad key_dest\n");
1866 // send function keydowns to interpreter no matter what mode is (unless the menu has specifically grabbed the keyboard, for rebinding keys)
1867 // VorteX: Omnicide does bind F* keys
1868 if (keydest != key_menu_grabbed)
1869 if (key >= K_F1 && key <= K_F12 && gamemode != GAME_BLOODOMNICIDE)
1873 if(keydown[key] == 1 && down)
1875 // button commands add keynum as a parm
1877 Cbuf_AddText (va("%s %i\n", bind, key));
1880 Cbuf_AddText (bind);
1881 Cbuf_AddText ("\n");
1883 } else if(bind[0] == '+' && !down && keydown[key] == 0)
1884 Cbuf_AddText(va("-%s %i\n", bind + 1, key));
1889 // send input to console if it wants it
1890 if (keydest == key_console)
1894 // con_closeontoggleconsole enables toggleconsole keys to close the
1895 // console, as long as they are not the color prefix character
1896 // (special exemption for german keyboard layouts)
1897 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))
1899 Con_ToggleConsole_f ();
1902 Key_Console (key, ascii);
1906 // handle toggleconsole in menu too
1907 if (keydest == key_menu)
1909 if (down && con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && ascii != STRING_COLOR_TAG)
1911 Con_ToggleConsole_f ();
1912 tbl_keydest[key] = key_void; // key release should go nowhere (especially not to key_menu or key_game)
1917 // ignore binds while a video is played, let the video system handle the key event
1918 if (cl_videoplaying)
1920 if (gamemode == GAME_BLOODOMNICIDE) // menu controls key events
1921 MR_KeyEvent(key, ascii, down);
1923 CL_Video_KeyEvent (key, ascii, keydown[key] != 0);
1927 // anything else is a key press into the game, chat line, or menu
1932 Key_Message (key, ascii);
1935 case key_menu_grabbed:
1936 MR_KeyEvent (key, ascii, down);
1939 q = CL_VM_InputEvent(down, key, ascii);
1940 // ignore key repeats on binds and only send the bind if the event hasnt been already processed by csqc
1943 if(keydown[key] == 1 && down)
1945 // button commands add keynum as a parm
1947 Cbuf_AddText (va("%s %i\n", bind, key));
1950 Cbuf_AddText (bind);
1951 Cbuf_AddText ("\n");
1953 } else if(bind[0] == '+' && !down && keydown[key] == 0)
1954 Cbuf_AddText(va("-%s %i\n", bind + 1, key));
1958 Con_Printf ("Key_Event: Bad key_dest\n");
1968 Key_ClearStates (void)
1970 memset(keydown, 0, sizeof(keydown));