📄 mapdef.java
字号:
/* MapDef.java
* Component: ProperJavaRDP
*
* Revision: $Revision: 1.4 $
* Author: $Author: telliott $
* Date: $Date: 2005/09/27 14:15:39 $
*
* Copyright (c) 2005 Propero Limited
*
* Purpose: Encapsulates an individual key mapping
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of 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 of
* MERCHANTABILITY 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 License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* (See gpl.txt for details of the GNU General Public License.)
*
*/
package net.propero.rdp.keymapping;
import java.awt.event.KeyEvent;
import java.io.PrintStream;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import net.propero.rdp.Constants;
import net.propero.rdp.Options;
public class MapDef {
// Flag masks for use in generating an integer modifiers value (for text definition output)
private final int FLAG_SHIFT = 0x01; // flag mask for a shift modifier
private final int FLAG_CTRL = 0x02; // flag mask for a control modifier
private final int FLAG_ALT = 0x04; // flag mask for an alt modifier
private final int FLAG_CAPSLOCK = 0x08; // flag mask for a capslock modifier
private int scancode;
private boolean ctrlDown;
private boolean shiftDown;
private boolean altDown;
private boolean capslockDown;
private char keyChar;
private int keyCode;
private boolean characterDef;
private int keyLocation;
/**
* Constructor for a character-defined mapping definition
*
* @param keyChar
* @param keyLocation
* @param scancode
* @param ctrlDown
* @param shiftDown
* @param altDown
* @param capslockDown
*/
public MapDef(char keyChar, int keyLocation, int scancode, boolean ctrlDown, boolean shiftDown, boolean altDown, boolean capslockDown) {
this.keyChar = keyChar;
this.characterDef = true;
this.keyLocation = keyLocation;
this.scancode = scancode;
this.ctrlDown = ctrlDown;
this.altDown = altDown;
this.shiftDown = shiftDown;
this.capslockDown = capslockDown;
}
/**
* Constructor for a keycode-defined mapping definition
*
* @param keyChar
* @param keyLocation
* @param scancode
* @param ctrlDown
* @param shiftDown
* @param altDown
* @param capslockDown
*/
public MapDef(int keyCode, int keyLocation, int scancode, boolean ctrlDown, boolean shiftDown, boolean altDown, boolean capslockDown) {
this.keyCode = keyCode;
this.characterDef = false;
this.keyLocation = keyLocation;
this.scancode = scancode;
this.ctrlDown = ctrlDown;
this.altDown = altDown;
this.shiftDown = shiftDown;
this.capslockDown = capslockDown;
}
public int getKeyCode(){ return keyCode; }
public char getKeyChar(){ return keyChar; }
/**
* Return the scancode associated with this mapping
* @return
*/
public int getScancode(){ return scancode; }
/**
* Return true if this mapping is defined by a character, false otherwise
* @return
*/
public boolean isCharacterDef(){ return characterDef; }
/**
* Return true if the keystroke defined in this mapping requires that the
* Control key be down
*
* @return
*/
public boolean isCtrlDown(){ return ctrlDown; }
/**
* Return true if the keystroke defined in this mapping requires that the
* Alt key be down
*
* @return
*/
public boolean isAltDown(){ return altDown; }
/**
* Return true if the keystroke defined in this mapping requires that the
* Shift key be down
*
* @return
*/
public boolean isShiftDown(){ return shiftDown; }
/**
* Return true if the keystroke defined in this mapping requires that
* Caps Lock is on
*
* @return
*/
public boolean isCapslockOn(){ return capslockDown; }
/**
* Return the number of modifiers that would need to be changed to
* send the specified character/key using this particular mapping.
*
* @param e Key event which was received by Java
* @param capslock Is the Caps Lock key down?
* @return The number of modifier changes to make
*/
public int modifierDistance(KeyEvent e, boolean capslock){
//boolean capslock = e.getComponent().getToolkit().getLockingKeyState( KeyEvent.VK_CAPS_LOCK);
if(!characterDef) return 0;
int dist = 0;
if(ctrlDown != e.isControlDown()) dist += 1;
if(altDown != e.isAltDown()) dist += 1;
if(shiftDown != e.isShiftDown()) dist += 1;
if(capslockDown != capslock) dist += 1;
return dist;
}
public boolean appliesTo(char c){
return ((characterDef) && (this.keyChar == c) && !(capslockDown));
}
/**
*
* Return true if this map definition applies to the supplied key event
*
* @param e KeyEvent to check definition against
* @return
*/
protected boolean appliesToTyped(KeyEvent e){
return ((characterDef) && (this.keyChar == e.getKeyChar()));
}
protected boolean appliesToTyped(KeyEvent e, boolean capslock){
if(Constants.OS == Constants.MAC){
// Remap the hash key to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -