⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 key.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Key.java * Copyright (C) 2003 *  * $Id: Key.java,v 1.12 2005/12/18 22:10:12 cawe Exp $ *//*Copyright (C) 1997-2001 Id Software, Inc.This program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*/package jake2.client;import jake2.Defines;import jake2.Globals;import jake2.game.Cmd;import jake2.qcommon.*;import jake2.util.Lib;import java.io.IOException;import java.io.RandomAccessFile;import java.util.Vector;/** * Key */public class Key extends Globals {	//	// these are the key numbers that should be passed to Key_Event	//	public static final int K_TAB = 9;	public static final int K_ENTER = 13;	public static final int K_ESCAPE = 27;	public static final int K_SPACE = 32;	// normal keys should be passed as lowercased ascii	public static final int K_BACKSPACE = 127;	public static final int K_UPARROW = 128;	public static final int K_DOWNARROW = 129;	public static final int K_LEFTARROW = 130;	public static final int K_RIGHTARROW = 131;	public static final int K_ALT = 132;	public static final int K_CTRL = 133;	public static final int K_SHIFT = 134;	public static final int K_F1 = 135;	public static final int K_F2 = 136;	public static final int K_F3 = 137;	public static final int K_F4 = 138;	public static final int K_F5 = 139;	public static final int K_F6 = 140;	public static final int K_F7 = 141;	public static final int K_F8 = 142;	public static final int K_F9 = 143;	public static final int K_F10 = 144;	public static final int K_F11 = 145;	public static final int K_F12 = 146;	public static final int K_INS = 147;	public static final int K_DEL = 148;	public static final int K_PGDN = 149;	public static final int K_PGUP = 150;	public static final int K_HOME = 151;	public static final int K_END = 152;	public static final int K_KP_HOME = 160;	public static final int K_KP_UPARROW = 161;	public static final int K_KP_PGUP = 162;	public static final int K_KP_LEFTARROW = 163;	public static final int K_KP_5 = 164;	public static final int K_KP_RIGHTARROW = 165;	public static final int K_KP_END = 166;	public static final int K_KP_DOWNARROW = 167;	public static final int K_KP_PGDN = 168;	public static final int K_KP_ENTER = 169;	public static final int K_KP_INS = 170;	public static final int K_KP_DEL = 171;	public static final int K_KP_SLASH = 172;	public static final int K_KP_MINUS = 173;	public static final int K_KP_PLUS = 174;	public static final int K_PAUSE = 255;	//	// mouse buttons generate virtual keys	//	public static final int K_MOUSE1 = 200;	public static final int K_MOUSE2 = 201;	public static final int K_MOUSE3 = 202;	//	// joystick buttons	//	public static final int K_JOY1 = 203;	public static final int K_JOY2 = 204;	public static final int K_JOY3 = 205;	public static final int K_JOY4 = 206;	public static final int K_MWHEELDOWN = 239;	public static final int K_MWHEELUP = 240;	static int anykeydown = 0;	static int key_waiting;	static int history_line = 0;	static boolean shift_down = false;	static int[] key_repeats = new int[256];	//static int[] keyshift = new int[256];	static boolean[] menubound = new boolean[256];	static boolean[] consolekeys = new boolean[256];	static String[] keynames = new String[256];	static {		keynames[K_TAB] = "TAB";		keynames[K_ENTER] = "ENTER";		keynames[K_ESCAPE] = "ESCAPE";		keynames[K_SPACE] = "SPACE";		keynames[K_BACKSPACE] = "BACKSPACE";		keynames[K_UPARROW] = "UPARROW";		keynames[K_DOWNARROW] = "DOWNARROW";		keynames[K_LEFTARROW] = "LEFTARROW";		keynames[K_RIGHTARROW] = "RIGHTARROW";		keynames[K_ALT] = "ALT";		keynames[K_CTRL] = "CTRL";		keynames[K_SHIFT] = "SHIFT";		keynames[K_F1] = "F1";		keynames[K_F2] = "F2";		keynames[K_F3] = "F3";		keynames[K_F4] = "F4";		keynames[K_F5] = "F5";		keynames[K_F6] = "F6";		keynames[K_F7] = "F7";		keynames[K_F8] = "F8";		keynames[K_F9] = "F9";		keynames[K_F10] = "F10";		keynames[K_F11] = "F11";		keynames[K_F12] = "F12";		keynames[K_INS] = "INS";		keynames[K_DEL] = "DEL";		keynames[K_PGDN] = "PGDN";		keynames[K_PGUP] = "PGUP";		keynames[K_HOME] = "HOME";		keynames[K_END] = "END";		keynames[K_MOUSE1] = "MOUSE1";		keynames[K_MOUSE2] = "MOUSE2";		keynames[K_MOUSE3] = "MOUSE3";		//	00092         {"JOY1", K_JOY1},		//	00093         {"JOY2", K_JOY2},		//	00094         {"JOY3", K_JOY3},		//	00095         {"JOY4", K_JOY4},		keynames[K_KP_HOME] = "KP_HOME";		keynames[K_KP_UPARROW] = "KP_UPARROW";		keynames[K_KP_PGUP] = "KP_PGUP";		keynames[K_KP_LEFTARROW] = "KP_LEFTARROW";		keynames[K_KP_5] = "KP_5";		keynames[K_KP_RIGHTARROW] = "KP_RIGHTARROW";		keynames[K_KP_END] = "KP_END";		keynames[K_KP_DOWNARROW] = "KP_DOWNARROW";		keynames[K_KP_PGDN] = "KP_PGDN";		keynames[K_KP_ENTER] = "KP_ENTER";		keynames[K_KP_INS] = "KP_INS";		keynames[K_KP_DEL] = "KP_DEL";		keynames[K_KP_SLASH] = "KP_SLASH";		keynames[K_KP_PLUS] = "KP_PLUS";		keynames[K_KP_MINUS] = "KP_MINUS";		keynames[K_MWHEELUP] = "MWHEELUP";		keynames[K_MWHEELDOWN] = "MWHEELDOWN";		keynames[K_PAUSE] = "PAUSE";		keynames[';'] = "SEMICOLON"; // because a raw semicolon seperates commands		keynames[0] = "NULL";	}	/**	 * 	 */	public static void Init() {		for (int i = 0; i < 32; i++) {			Globals.key_lines[i][0] = ']';			Globals.key_lines[i][1] = 0;		}		Globals.key_linepos = 1;		//		// init ascii characters in console mode		//		for (int i = 32; i < 128; i++)			consolekeys[i] = true;		consolekeys[K_ENTER] = true;		consolekeys[K_KP_ENTER] = true;		consolekeys[K_TAB] = true;		consolekeys[K_LEFTARROW] = true;		consolekeys[K_KP_LEFTARROW] = true;		consolekeys[K_RIGHTARROW] = true;		consolekeys[K_KP_RIGHTARROW] = true;		consolekeys[K_UPARROW] = true;		consolekeys[K_KP_UPARROW] = true;		consolekeys[K_DOWNARROW] = true;		consolekeys[K_KP_DOWNARROW] = true;		consolekeys[K_BACKSPACE] = true;		consolekeys[K_HOME] = true;		consolekeys[K_KP_HOME] = true;		consolekeys[K_END] = true;		consolekeys[K_KP_END] = true;		consolekeys[K_PGUP] = true;		consolekeys[K_KP_PGUP] = true;		consolekeys[K_PGDN] = true;		consolekeys[K_KP_PGDN] = true;		consolekeys[K_SHIFT] = true;		consolekeys[K_INS] = true;		consolekeys[K_KP_INS] = true;		consolekeys[K_KP_DEL] = true;		consolekeys[K_KP_SLASH] = true;		consolekeys[K_KP_PLUS] = true;		consolekeys[K_KP_MINUS] = true;		consolekeys[K_KP_5] = true;		consolekeys['`'] = false;		consolekeys['~'] = false;//		for (int i = 0; i < 256; i++)//			keyshift[i] = i;//		for (int i = 'a'; i <= 'z'; i++)//			keyshift[i] = i - 'a' + 'A';//		keyshift['1'] = '!';//		keyshift['2'] = '@';//		keyshift['3'] = '#';//		keyshift['4'] = '$';//		keyshift['5'] = '%';//		keyshift['6'] = '^';//		keyshift['7'] = '&';//		keyshift['8'] = '*';//		keyshift['9'] = '(';//		keyshift['0'] = ')';//		keyshift['-'] = '_';//		keyshift['='] = '+';//		keyshift[','] = '<';//		keyshift['.'] = '>';//		keyshift['/'] = '?';//		keyshift[';'] = ':';//		keyshift['\''] = '"';//		keyshift['['] = '{';//		keyshift[']'] = '}';//		keyshift['`'] = '~';//		keyshift['\\'] = '|';		menubound[K_ESCAPE] = true;		for (int i = 0; i < 12; i++)			menubound[K_F1 + i] = true;		//		// register our functions		//		Cmd.AddCommand("bind", Key.Bind_f);		Cmd.AddCommand("unbind", Key.Unbind_f);		Cmd.AddCommand("unbindall", Key.Unbindall_f);		Cmd.AddCommand("bindlist", Key.Bindlist_f);	}	public static void ClearTyping() {		Globals.key_lines[Globals.edit_line][1] = 0; // clear any typing		Globals.key_linepos = 1;	}	/**	 * Called by the system between frames for both key up and key down events.	 */	public static void Event(int key, boolean down, int time) {				String kb;		String cmd;		// hack for modal presses		if (key_waiting == -1) {			if (down)				key_waiting = key;			return;		}		// update auto-repeat status		if (down) {			key_repeats[key]++;			if (key_repeats[key] > 1				&& Globals.cls.key_dest == Defines.key_game				&& !(Globals.cls.state == Defines.ca_disconnected))				return; // ignore most autorepeats			if (key >= 200 && Globals.keybindings[key] == null)				Com.Printf(Key.KeynumToString(key) + " is unbound, hit F4 to set.\n");		}		else {			key_repeats[key] = 0;		}		if (key == K_SHIFT)			shift_down = down;		// console key is hardcoded, so the user can never unbind it		if (key == '`' || key == '~') {			if (!down)				return;			Console.ToggleConsole_f.execute();			return;		}		// any key during the attract mode will bring up the menu		if (Globals.cl.attractloop && Globals.cls.key_dest != Defines.key_menu && !(key >= K_F1 && key <= K_F12))			key = K_ESCAPE;		// menu key is hardcoded, so the user can never unbind it		if (key == K_ESCAPE) {			if (!down)				return;			if (Globals.cl.frame.playerstate.stats[Defines.STAT_LAYOUTS] != 0 && Globals.cls.key_dest == Defines.key_game) {				// put away help computer / inventory				Cbuf.AddText("cmd putaway\n");				return;			}			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 :					Menu.Menu_Main_f();					break;				default :					Com.Error(Defines.ERR_FATAL, "Bad cls.key_dest");			}			return;		}		// track if any key is down for BUTTON_ANY		Globals.keydown[key] = down;		if (down) {			if (key_repeats[key] == 1)				Key.anykeydown++;		}		else {			Key.anykeydown--;			if (Key.anykeydown < 0)				Key.anykeydown = 0;		}		//		// key up events only generate commands if the game key binding is		// a button command (leading + sign).  These will occur even in console mode,		// to keep the character from continuing an action started before a console		// switch.  Button commands include the kenum as a parameter, so multiple		// downs can be matched with ups		//		if (!down) {			kb = Globals.keybindings[key];			if (kb != null && kb.length()>0 && kb.charAt(0) == '+') {				cmd = "-" + kb.substring(1) + " " + key + " " + time + "\n";				Cbuf.AddText(cmd);			}//			if (keyshift[key] != key) {//				kb = Globals.keybindings[keyshift[key]];//				if (kb != null && kb.length()>0 && kb.charAt(0) == '+') {//					cmd = "-" + kb.substring(1) + " " + key + " " + time + "\n";//					Cbuf.AddText(cmd);//				}//			}			return;		}		//		// if not a consolekey, send to the interpreter no matter what mode is		//		if ((Globals.cls.key_dest == Defines.key_menu && menubound[key])			|| (Globals.cls.key_dest == Defines.key_console && !consolekeys[key])			|| (Globals.cls.key_dest == Defines.key_game && (Globals.cls.state == Defines.ca_active || !consolekeys[key]))) {			kb = Globals.keybindings[key];			if (kb != null) {				if (kb.length()>0 && kb.charAt(0) == '+') {					// button commands add keynum and time as a parm					cmd = kb + " " + key + " " + time + "\n";					Cbuf.AddText(cmd);				}				else {					Cbuf.AddText(kb + "\n");				}			}			return;		}		if (!down)			return; // other systems only care about key down events

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -