keymap.java.svn-base
来自「一个JAVA程序员的游戏」· SVN-BASE 代码 · 共 99 行
SVN-BASE
99 行
/*
* KeyMap.java
*
* Created on 21. Januar 2007, 17:53
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package kanjitori.preferences;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author Pirx
*/
public class KeyMap implements Serializable {
private static final long serialVersionUID = 1;
public static final String[] KEYS = new String[]{
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q",
"R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8",
"9","0","LeftCtrl","RightCtrl","Alt","Space","Tab",
"Left","Right","Up","Down","Return"
};
public static final int[] KEY_INPUT = new int[]{
0x1E,0x30,0x2E,0x20,0x12,0x21,0x22,0x23,0x17,0x24,0x25,0x26,0x32,0x31,0x18,0x19, 0x10,
0x13,0x1F,0x14,0x16,0x2F, 0x11,0x2D,0x15,0x2C, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0A, 0x0B,0x1D,0x9D,0x38,0x39, 0x0F,
0xCB,0xCD,0xC8,0xD0,0x1C
};
public static final String[] ACTIONS = new String[]{
"forward", "backward",
"strafeLeft", "strafeRight",
"turnLeft", "turnRight", "turnUp", "turnDown",
"teleport", "defChange"
};
public void setDefaults() {
clear();
bind(0x11, ACTIONS[0]); //W -> forward
bind(0x1F, ACTIONS[1]); //S -> backward
bind(0x1E, ACTIONS[2]); //A -> strafeLeft
bind(0x20, ACTIONS[3]); //D -> strafeRight
bind(0xC8, ACTIONS[0]); //UP -> forward
bind(0xD0, ACTIONS[1]); //DOWN -> backward
bind(0xCB, ACTIONS[4]); //LEFT -> turnLeft
bind(0xCD, ACTIONS[5]); //RIGHT -> turnRight
bind(0x02, ACTIONS[8]); //1 -> teleport
bind(0x03, ACTIONS[9]); //2 -> defChange
}
private Map<Integer, String> map = new HashMap<Integer, String>();
private boolean mouseInverted = false;
public void bind(int keyInput, String action) {
map.put(keyInput, action);
}
public void unbind(int keyInput) {
map.remove(keyInput);
}
public boolean isMouseInverted() {
return mouseInverted;
}
public void setMouseInverted(boolean mouseInverted) {
this.mouseInverted = mouseInverted;
}
public String getAction(int keyInput) {
return map.get(keyInput);
}
public void clear() {
map.clear();
mouseInverted = false;
}
public static int getActionIndex(String action) {
for (int i = 0; i < ACTIONS.length; i++) {
if (ACTIONS[i].equals(action)) {
return i;
}
}
return -1;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?