+ return linepos;
+ }
+
+ if (key == K_HOME || key == K_KP_HOME)
+ {
+ if (is_console && KM_CTRL)
+ {
+ con_backscroll = CON_TEXTSIZE;
+ return linepos;
+ }
+ if (KM_NONE)
+ return linestart;
+ }
+
+ if (key == K_END || key == K_KP_END)
+ {
+ if (is_console && KM_CTRL)
+ {
+ con_backscroll = 0;
+ return linepos;
+ }
+ if (KM_NONE)
+ return (int)strlen(line);
+ }
+
+ return -1;
+}
+
+static int Key_Convert_NumPadKey(int key)
+{
+ // LadyHavoc: copied most of this from Q2 to improve keyboard handling
+ switch (key)
+ {
+ case K_KP_SLASH: return '/';
+ case K_KP_MINUS: return '-';
+ case K_KP_PLUS: return '+';
+ case K_KP_HOME: return '7';
+ case K_KP_UPARROW: return '8';
+ case K_KP_PGUP: return '9';
+ case K_KP_LEFTARROW: return '4';
+ case K_KP_5: return '5';
+ case K_KP_RIGHTARROW: return '6';
+ case K_KP_END: return '1';
+ case K_KP_DOWNARROW: return '2';
+ case K_KP_PGDN: return '3';
+ case K_KP_INS: return '0';
+ case K_KP_DEL: return '.';
+ }
+ return key;
+}
+
+static void
+Key_Console(cmd_state_t *cmd, int key, int unicode)
+{
+ int linepos;
+
+ key = Key_Convert_NumPadKey(key);
+
+ // Forbid Ctrl Alt shortcuts since on Windows they are used to type some characters
+ // in certain non-English keyboards using the AltGr key (which emulates Ctrl Alt)
+ // Reference: "Why Ctrl+Alt shouldn't be used as a shortcut modifier"
+ // https://blogs.msdn.microsoft.com/oldnewthing/20040329-00/?p=40003
+ if (keydown[K_CTRL] && keydown[K_ALT])
+ goto add_char;
+
+ linepos = Key_Parse_CommonKeys(cmd, true, key, unicode);
+ if (linepos >= 0)
+ {
+ key_linepos = linepos;
+ return;
+ }
+
+ if ((key == K_ENTER || key == K_KP_ENTER) && KM_NONE)
+ {
+ Cbuf_AddText (cmd, key_line+1); // skip the ]
+ Cbuf_AddText (cmd, "\n");
+ Key_History_Push();
+ key_linepos = Key_ClearEditLine(true);
+ // force an update, because the command may take some time
+ if (cls.state == ca_disconnected)
+ CL_UpdateScreen ();
+ return;
+ }
+
+ if (key == 'l' && KM_CTRL)
+ {
+ Cbuf_AddText (cmd, "clear\n");
+ return;
+ }
+
+ if (key == 'q' && KM_CTRL) // like zsh ^q: push line to history, don't execute, and clear
+ {
+ // clear line
+ Key_History_Push();
+ key_linepos = Key_ClearEditLine(true);