📄 key.java
字号:
// if (shift_down)// key = keyshift[key]; switch (Globals.cls.key_dest) { case Defines.key_message : Key.Message(key); break; case Defines.key_menu : Menu.Keydown(key); break; case Defines.key_game : case Defines.key_console : Key.Console(key); break; default : Com.Error(Defines.ERR_FATAL, "Bad cls.key_dest"); } } /** * Returns a string (either a single ascii char, or a K_* name) for the * given keynum. */ public static String KeynumToString(int keynum) { if (keynum < 0 || keynum > 255) return "<KEY NOT FOUND>"; if (keynum > 32 && keynum < 127) return Character.toString((char) keynum); if (keynames[keynum] != null) return keynames[keynum]; return "<UNKNOWN KEYNUM>"; } /** * Returns a key number to be used to index keybindings[] by looking at * the given string. Single ascii characters return themselves, while * the K_* names are matched up. */ static int StringToKeynum(String str) { if (str == null) return -1; if (str.length() == 1) return str.charAt(0); for (int i = 0; i < keynames.length; i++) { if (str.equalsIgnoreCase(keynames[i])) return i; } return -1; } public static void Message(int key) { if (key == K_ENTER || key == K_KP_ENTER) { if (Globals.chat_team) Cbuf.AddText("say_team \""); else Cbuf.AddText("say \""); Cbuf.AddText(Globals.chat_buffer); Cbuf.AddText("\"\n"); Globals.cls.key_dest = Defines.key_game; Globals.chat_buffer = ""; return; } if (key == K_ESCAPE) { Globals.cls.key_dest = Defines.key_game; Globals.chat_buffer = ""; return; } if (key < 32 || key > 127) return; // non printable if (key == K_BACKSPACE) { if (Globals.chat_buffer.length() > 2) { Globals.chat_buffer = Globals.chat_buffer.substring(0, Globals.chat_buffer.length() - 2); } else Globals.chat_buffer = ""; return; } if (Globals.chat_buffer.length() > Defines.MAXCMDLINE) return; // all full Globals.chat_buffer += (char) key; } /** * Interactive line editing and console scrollback. */ public static void Console(int key) { switch (key) { case K_KP_SLASH : key = '/'; break; case K_KP_MINUS : key = '-'; break; case K_KP_PLUS : key = '+'; break; case K_KP_HOME : key = '7'; break; case K_KP_UPARROW : key = '8'; break; case K_KP_PGUP : key = '9'; break; case K_KP_LEFTARROW : key = '4'; break; case K_KP_5 : key = '5'; break; case K_KP_RIGHTARROW : key = '6'; break; case K_KP_END : key = '1'; break; case K_KP_DOWNARROW : key = '2'; break; case K_KP_PGDN : key = '3'; break; case K_KP_INS : key = '0'; break; case K_KP_DEL : key = '.'; break; } if (key == 'l') { if (Globals.keydown[K_CTRL]) { Cbuf.AddText("clear\n"); return; } } if (key == K_ENTER || key == K_KP_ENTER) { // backslash text are commands, else chat if (Globals.key_lines[Globals.edit_line][1] == '\\' || Globals.key_lines[Globals.edit_line][1] == '/') Cbuf.AddText( new String(Globals.key_lines[Globals.edit_line], 2, Lib.strlen(Globals.key_lines[Globals.edit_line]) - 2)); else Cbuf.AddText( new String(Globals.key_lines[Globals.edit_line], 1, Lib.strlen(Globals.key_lines[Globals.edit_line]) - 1)); Cbuf.AddText("\n"); Com.Printf(new String(Globals.key_lines[Globals.edit_line], 0, Lib.strlen(Globals.key_lines[Globals.edit_line])) + "\n"); Globals.edit_line = (Globals.edit_line + 1) & 31; history_line = Globals.edit_line; Globals.key_lines[Globals.edit_line][0] = ']'; Globals.key_linepos = 1; if (Globals.cls.state == Defines.ca_disconnected) SCR.UpdateScreen(); // force an update, because the command may take some time return; } if (key == K_TAB) { // command completion CompleteCommand(); return; } if ((key == K_BACKSPACE) || (key == K_LEFTARROW) || (key == K_KP_LEFTARROW) || ((key == 'h') && (Globals.keydown[K_CTRL]))) { if (Globals.key_linepos > 1) Globals.key_linepos--; return; } if ((key == K_UPARROW) || (key == K_KP_UPARROW) || ((key == 'p') && Globals.keydown[K_CTRL])) { do { history_line = (history_line - 1) & 31; } while (history_line != Globals.edit_line && Globals.key_lines[history_line][1] == 0); if (history_line == Globals.edit_line) history_line = (Globals.edit_line + 1) & 31; //Lib.strcpy(Globals.key_lines[Globals.edit_line], Globals.key_lines[history_line]); System.arraycopy(Globals.key_lines[history_line], 0, Globals.key_lines[Globals.edit_line], 0, Globals.key_lines[Globals.edit_line].length); Globals.key_linepos = Lib.strlen(Globals.key_lines[Globals.edit_line]); return; } if ((key == K_DOWNARROW) || (key == K_KP_DOWNARROW) || ((key == 'n') && Globals.keydown[K_CTRL])) { if (history_line == Globals.edit_line) return; do { history_line = (history_line + 1) & 31; } while (history_line != Globals.edit_line && Globals.key_lines[history_line][1] == 0); if (history_line == Globals.edit_line) { Globals.key_lines[Globals.edit_line][0] = ']'; Globals.key_linepos = 1; } else { //Lib.strcpy(Globals.key_lines[Globals.edit_line], Globals.key_lines[history_line]); System.arraycopy(Globals.key_lines[history_line], 0, Globals.key_lines[Globals.edit_line], 0, Globals.key_lines[Globals.edit_line].length); Globals.key_linepos = Lib.strlen(Globals.key_lines[Globals.edit_line]); } return; } if (key == K_PGUP || key == K_KP_PGUP) { Globals.con.display -= 2; return; } if (key == K_PGDN || key == K_KP_PGDN) { Globals.con.display += 2; if (Globals.con.display > Globals.con.current) Globals.con.display = Globals.con.current; return; } if (key == K_HOME || key == K_KP_HOME) { Globals.con.display = Globals.con.current - Globals.con.totallines + 10; return; } if (key == K_END || key == K_KP_END) { Globals.con.display = Globals.con.current; return; } if (key < 32 || key > 127) return; // non printable if (Globals.key_linepos < Defines.MAXCMDLINE - 1) { Globals.key_lines[Globals.edit_line][Globals.key_linepos] = (byte) key; Globals.key_linepos++; Globals.key_lines[Globals.edit_line][Globals.key_linepos] = 0; } } private static void printCompletions(String type, Vector compl) { Com.Printf(type); for (int i = 0; i < compl.size(); i++) { Com.Printf((String)compl.get(i) + " "); } Com.Printf("\n"); } static void CompleteCommand() { int start = 1; if (key_lines[edit_line][start] == '\\' || key_lines[edit_line][start] == '/') start++; int end = start; while (key_lines[edit_line][end] != 0) end++; String s = new String(key_lines[edit_line], start, end-start); Vector cmds = Cmd.CompleteCommand(s); Vector vars = Cvar.CompleteVariable(s); int c = cmds.size(); int v = vars.size(); if ((c + v) > 1) { if (c > 0) printCompletions("\nCommands:\n", cmds); if (v > 0) printCompletions("\nVariables:\n", vars); return; } else if (c == 1) { s = (String)cmds.get(0); } else if (v == 1) { s = (String)vars.get(0); } else return; key_lines[edit_line][1] = '/'; byte[] bytes = Lib.stringToBytes(s); System.arraycopy(bytes, 0, key_lines[edit_line], 2, bytes.length); key_linepos = bytes.length + 2; key_lines[edit_line][key_linepos++] = ' '; key_lines[edit_line][key_linepos] = 0; return; } public static xcommand_t Bind_f = new xcommand_t() { public void execute() { Key_Bind_f(); } }; static void Key_Bind_f() { int c = Cmd.Argc(); if (c < 2) { Com.Printf("bind <key> [command] : attach a command to a key\n"); return; } int b = StringToKeynum(Cmd.Argv(1)); if (b == -1) { Com.Printf("\"" + Cmd.Argv(1) + "\" isn't a valid key\n"); return; } if (c == 2) { if (Globals.keybindings[b] != null) Com.Printf("\"" + Cmd.Argv(1) + "\" = \"" + Globals.keybindings[b] + "\"\n"); else Com.Printf("\"" + Cmd.Argv(1) + "\" is not bound\n"); return; } // copy the rest of the command line String cmd = ""; // start out with a null string for (int i = 2; i < c; i++) { cmd += Cmd.Argv(i); if (i != (c - 1)) cmd += " "; } SetBinding(b, cmd); } static void SetBinding(int keynum, String binding) { if (keynum == -1) return; // free old bindings Globals.keybindings[keynum] = null; Globals.keybindings[keynum] = binding; } static xcommand_t Unbind_f = new xcommand_t() { public void execute() { Key_Unbind_f(); } }; static void Key_Unbind_f() { if (Cmd.Argc() != 2) { Com.Printf("unbind <key> : remove commands from a key\n"); return; } int b = Key.StringToKeynum(Cmd.Argv(1)); if (b == -1) { Com.Printf("\"" + Cmd.Argv(1) + "\" isn't a valid key\n"); return; } Key.SetBinding(b, null); } static xcommand_t Unbindall_f = new xcommand_t() { public void execute() { Key_Unbindall_f(); } }; static void Key_Unbindall_f() { for (int i = 0; i < 256; i++) Key.SetBinding(i, null); } static xcommand_t Bindlist_f = new xcommand_t() { public void execute() { Key_Bindlist_f(); } }; static void Key_Bindlist_f() { for (int i = 0; i < 256; i++) if (Globals.keybindings[i] != null && Globals.keybindings[i].length() != 0) Com.Printf(Key.KeynumToString(i) + " \"" + Globals.keybindings[i] + "\"\n"); } static void ClearStates() { int i; Key.anykeydown = 0; for (i = 0; i < 256; i++) { if (keydown[i] || key_repeats[i]!=0) Event(i, false, 0); keydown[i] = false; key_repeats[i] = 0; } } public static void WriteBindings(RandomAccessFile f) { for (int i = 0; i < 256; i++) if (keybindings[i] != null && keybindings[i].length() > 0) try { f.writeBytes("bind " + KeynumToString(i) + " \"" + keybindings[i] + "\"\n"); } catch (IOException e) {} }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -