📄 keycode_filebased.java
字号:
changes += ((char) 0x1d) + down;
}
if (Options.altkey_quiet) {
if (state[ALT][BEFORE] != state[ALT][AFTER]) {
if (state[ALT][BEFORE])
changes += (char) 0x38 + quietup + ((char) 0x38)
+ quietdown + ((char) 0x38) + up;
else {
if (e.getID() == KeyEvent.KEY_RELEASED) {
altQuiet = true;
changes += ((char) 0x38) + quietdown;
} else {
altQuiet = false;
changes += ((char) 0x38) + down;
}
}
} else if (state[ALT][AFTER] && altQuiet) {
altQuiet = false;
changes += (char) 0x38 + quietup + ((char) 0x38) + quietdown
+ ((char) 0x38) + up + ((char) 0x38) + down;
}
} else {
if (state[ALT][BEFORE] != state[ALT][AFTER]) {
if (state[ALT][BEFORE])
changes += ((char) 0x38) + up;
else
changes += ((char) 0x38) + down;
}
}
if (state[CAPSLOCK][BEFORE] != state[CAPSLOCK][AFTER]) {
changes += ((char) 0x3a) + down + ((char) 0x3a) + up;
}
return changes;
}
/**
* Output key map definitions to a file as a series of single line text
* descriptions
*
* @param filename
* File in which to store definitions
*/
public void writeToFile(String filename) {
try {
FileOutputStream out = new FileOutputStream(filename);
PrintStream p = new PrintStream(out);
Iterator i = keyMap.iterator();
while (i.hasNext()) {
((MapDef) i.next()).writeToStream(p);
}
p.close();
} catch (Exception e) {
System.err.println("Error writing to file: " + e.getMessage());
}
}
/**
* Retrieve the scancode corresponding to the supplied character as defined
* within this object. Also update the mod array to hold any modifier keys
* that are required to send alongside it.
*
* @param c
* Character to obtain scancode for
* @param mod
* List of modifiers to be updated by method
* @return Scancode of supplied key
*/
public boolean hasScancode(char c) {
if (c == KeyEvent.CHAR_UNDEFINED)
return false;
Iterator i = keyMap.iterator();
MapDef best = null;
while (i.hasNext()) {
MapDef current = (MapDef) i.next();
if (current.appliesTo(c)) {
best = current;
}
}
return (best != null);
}
/**
* Retrieve the scancode corresponding to the supplied character as defined
* within this object. Also update the mod array to hold any modifier keys
* that are required to send alongside it.
*
* @param c
* Character to obtain scancode for
* @param mod
* List of modifiers to be updated by method
* @return Scancode of supplied key
*/
public int charToScancode(char c, String[] mod) {
Iterator i = keyMap.iterator();
int smallestDist = -1;
MapDef best = null;
while (i.hasNext()) {
MapDef current = (MapDef) i.next();
if (current.appliesTo(c)) {
best = current;
}
}
if (best != null) {
if (best.isShiftDown())
mod[0] = "SHIFT";
else if (best.isCtrlDown() && best.isAltDown())
mod[0] = "ALTGR";
else
mod[0] = "NONE";
return best.getScancode();
} else
return -1;
}
/**
* Return a mapping definition associated with the supplied key event from
* within the list stored in this object.
*
* @param e
* Key event to retrieve a definition for
* @return Mapping definition for supplied keypress
*/
public MapDef getDef(KeyEvent e) {
if (e.getID() == KeyEvent.KEY_RELEASED) {
MapDef def = (MapDef) keysCurrentlyDown.get(new Integer(e
.getKeyCode()));
registerKeyEvent(e, def);
if (e.getID() == KeyEvent.KEY_RELEASED)
logger.debug("Released: " + e.getKeyCode()
+ " returned scancode: "
+ ((def != null) ? "" + def.getScancode() : "null"));
return def;
}
updateCapsLock(e);
Iterator i = keyMap.iterator();
int smallestDist = -1;
MapDef best = null;
boolean noScanCode = !hasScancode(e.getKeyChar());
while (i.hasNext()) {
MapDef current = (MapDef) i.next();
boolean applies;
if ((e.getID() == KeyEvent.KEY_PRESSED)) {
applies = current.appliesToPressed(e);
} else if ((!lastEventMatched) && (e.getID() == KeyEvent.KEY_TYPED)) {
applies = current.appliesToTyped(e, capsLockDown);
} else
applies = false;
if (applies) {
int d = current.modifierDistance(e, capsLockDown);
if ((smallestDist == -1) || (d < smallestDist)) {
smallestDist = d;
best = current;
}
}
}
if (e.getID() == KeyEvent.KEY_PRESSED)
logger.debug("Pressed: " + e.getKeyCode() + " returned scancode: "
+ ((best != null) ? "" + best.getScancode() : "null"));
if (e.getID() == KeyEvent.KEY_TYPED)
logger.debug("Typed: " + e.getKeyChar() + " returned scancode: "
+ ((best != null) ? "" + best.getScancode() : "null"));
registerKeyEvent(e, best);
return best;
}
/**
* Return a scancode for the supplied key event, from within the mapping
* definitions stored in this object.
*
* @param e
* Key event for which to determine a scancode
* @return Scancode for the supplied keypress, according to current mappings
*/
public int getScancode(KeyEvent e) {
String[] mod = { "" };
MapDef d = getDef(e);
if (d != null) {
return d.getScancode();
} else
return -1;
}
private void registerKeyEvent(KeyEvent e, MapDef m) {
if (e.getID() == KeyEvent.KEY_RELEASED) {
keysCurrentlyDown.remove(new Integer(e.getKeyCode()));
if ((!Options.caps_sends_up_and_down)
&& (e.getKeyCode() == KeyEvent.VK_CAPS_LOCK)) {
logger.debug("Turning CAPSLOCK off - key release");
capsLockDown = false;
}
lastEventMatched = false;
}
if (e.getID() == KeyEvent.KEY_PRESSED) {
lastKeyEvent = e;
if (m != null)
lastEventMatched = true;
else
lastEventMatched = false;
if ((Options.caps_sends_up_and_down)
&& (e.getKeyCode() == KeyEvent.VK_CAPS_LOCK)) {
logger.debug("Toggling CAPSLOCK");
capsLockDown = !capsLockDown;
} else if (e.getKeyCode() == KeyEvent.VK_CAPS_LOCK) {
logger.debug("Turning CAPSLOCK on - key press");
capsLockDown = true;
}
}
if (lastKeyEvent != null
&& m != null
&& !keysCurrentlyDown.containsKey(new Integer(lastKeyEvent
.getKeyCode()))) {
keysCurrentlyDown.put(new Integer(lastKeyEvent.getKeyCode()), m);
lastKeyEvent = null;
}
}
/**
* Construct a list of keystrokes needed to reproduce an AWT key event via RDP
* @param e Keyboard event to reproduce
* @return List of character pairs representing scancodes and key actions to send to server
*/
public String getKeyStrokes(KeyEvent e) {
String codes = "";
MapDef d = getDef(e);
if (d == null)
return "";
codes = stateChanges(e, d);
String type = "";
if (e.getID() == KeyEvent.KEY_RELEASED) {
if ((!Options.caps_sends_up_and_down)
&& (e.getKeyCode() == KeyEvent.VK_CAPS_LOCK)) {
logger.debug("Sending CAPSLOCK toggle");
codes = "" + ((char) 0x3a) + ((char) DOWN) + ((char) 0x3a)
+ ((char) UP) + codes;
} else {
type = "" + ((char) UP);
codes = ((char) d.getScancode()) + type + codes;
}
} else {
if ((!Options.caps_sends_up_and_down)
&& (e.getKeyCode() == KeyEvent.VK_CAPS_LOCK)) {
logger.debug("Sending CAPSLOCK toggle");
codes += "" + ((char) 0x3a) + ((char) DOWN) + ((char) 0x3a)
+ ((char) UP);
} else {
type = "" + ((char) DOWN);
codes += ((char) d.getScancode()) + type;
}
}
return codes;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -