Java Code Examples for java.awt.event.KeyEvent#getKeyLocation()

The following examples show how to use java.awt.event.KeyEvent#getKeyLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyStroker.java    From tn5250j with GNU General Public License v2.0 6 votes vote down vote up
public KeyStroker(KeyEvent ke) {


    this.keyCode = ke.getKeyCode();
    this.isShiftDown = ke.isShiftDown();
    this.isControlDown = ke.isControlDown();
    this.isAltDown = ke.isAltDown();
    this.isAltGrDown = ke.isAltGraphDown();
    this.location = ke.getKeyLocation();

    hashCode = keyCode +
        (isShiftDown ? 1 : 0) +
        (isControlDown ? 1 : 0) +
        (isAltDown ? 1 : 0) +
        (isAltGrDown ? 1 : 0) +
        location;

  }
 
Example 2
Source File: KeyStroker.java    From tn5250j with GNU General Public License v2.0 6 votes vote down vote up
public KeyStroker(KeyEvent ke, boolean isAltGrDown) {


    this.keyCode = ke.getKeyCode();
    this.isShiftDown = ke.isShiftDown();
    this.isControlDown = ke.isControlDown();
    this.isAltDown = ke.isAltDown();
    this.isAltGrDown = isAltGrDown;
    this.location = ke.getKeyLocation();

    hashCode = keyCode +
        (isShiftDown ? 1 : 0) +
        (isControlDown ? 1 : 0) +
        (isAltDown ? 1 : 0) +
        (isAltGrDown ? 1 : 0) +
        location;

  }
 
Example 3
Source File: KeyStroker.java    From tn5250j with GNU General Public License v2.0 6 votes vote down vote up
public void setAttributes(KeyEvent ke, boolean isAltGr) {

    keyCode = ke.getKeyCode();
    isShiftDown = ke.isShiftDown();
    isControlDown = ke.isControlDown();
    isAltDown = ke.isAltDown();
    isAltGrDown = isAltGr;
    location = ke.getKeyLocation();

    hashCode = keyCode +
        (isShiftDown ? 1 : 0) +
        (isControlDown ? 1 : 0) +
        (isAltDown ? 1 : 0) +
        (isAltGrDown ? 1 : 0) +
        location;
  }
 
Example 4
Source File: ConsoleTextPane.java    From energy2d with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Custom key event processing for command history implementation. Captures
 * key up and key down * strokes to call command history and redefines the
 * same events with control down to allow caret * vertical shift.
 */
protected void processKeyEvent(KeyEvent e) {
	// Id Control key is down, captures events does command history recall
	// and inhibits caret vertical shift.
	if (e.getKeyCode() == KeyEvent.VK_UP && e.getID() == KeyEvent.KEY_PRESSED
			&& !e.isControlDown()) {
		recallCommand(true);
	} else if (e.getKeyCode() == KeyEvent.VK_DOWN && e.getID() == KeyEvent.KEY_PRESSED
			&& !e.isControlDown()) {
		recallCommand(false);
	}
	// If Control key is down, redefines the event as if it where a key up
	// or key down stroke without
	// modifiers. This allows to move the caret up and down with no command
	// history recall.
	else if ((e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP)
			&& e.getID() == KeyEvent.KEY_PRESSED && e.isControlDown()) {
		super.processKeyEvent(new KeyEvent((Component) e.getSource(), e.getID(), e.getWhen(),
				0, // No modifiers
				e.getKeyCode(), e.getKeyChar(), e.getKeyLocation()));
	}
	// Standard processing for other events.
	else {
		super.processKeyEvent(e);
	}
}
 
Example 5
Source File: KeyStroker.java    From tn5250j with GNU General Public License v2.0 5 votes vote down vote up
public boolean equals(KeyEvent ke) {

    return (keyCode == ke.getKeyCode() &&
        isShiftDown == ke.isShiftDown() &&
        isControlDown == ke.isControlDown() &&
        isAltDown == ke.isAltDown() &&
        isAltGrDown == ke.isAltGraphDown() &&
        location == ke.getKeyLocation());
  }
 
Example 6
Source File: KeyStroker.java    From tn5250j with GNU General Public License v2.0 5 votes vote down vote up
public boolean equals(KeyEvent ke, boolean altGrDown) {

    return (keyCode == ke.getKeyCode() &&
        isShiftDown == ke.isShiftDown() &&
        isControlDown == ke.isControlDown() &&
        isAltDown == ke.isAltDown() &&
        isAltGrDown == altGrDown &&
        location == ke.getKeyLocation());
  }
 
Example 7
Source File: Signals.java    From mochadoom with GNU General Public License v3.0 5 votes vote down vote up
public static ScanCode getScanCode(KeyEvent e) {
    final ScanCode ret = ScanCode.v[map[e.getKeyCode()] & 0xFF];

    if (ret.location == e.getKeyLocation()) {
        return ret;
    }

    // try sibling
    final ScanCode sib = ScanCode.v[siblings[ret.ordinal()] & 0xFF];
    if (sib.location == e.getKeyLocation()) {
        return sib;
    }
    
    return ScanCode.SC_NULL;
}
 
Example 8
Source File: MenuBar.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected @Override boolean processKeyBinding(KeyStroke ks,
                                KeyEvent e,
                                int condition,
                                boolean pressed) {
    if (Utilities.isMac()) {
        int mods = e.getModifiers();
        boolean isCtrl = (mods & KeyEvent.CTRL_MASK) != 0;
        boolean isAlt = (mods & KeyEvent.ALT_MASK) != 0;
        if (isAlt && (e instanceof MarkedKeyEvent)) {
            mods = mods & ~ KeyEvent.CTRL_MASK;
            mods = mods & ~ KeyEvent.CTRL_DOWN_MASK;
            mods |= KeyEvent.ALT_MASK;
            mods |= KeyEvent.ALT_DOWN_MASK;
            
            KeyEvent newEvent = new MarkedKeyEvent (
                (Component) e.getSource(), e.getID(), 
                e.getWhen(), mods, e.getKeyCode(), e.getKeyChar(), 
                e.getKeyLocation());
            
            KeyStroke newStroke = null;
            if( null != ks ) {
                newStroke = e.getID() == KeyEvent.KEY_TYPED ?
                    KeyStroke.getKeyStroke (ks.getKeyChar(), mods) :
                    KeyStroke.getKeyStroke (ks.getKeyCode(), mods,
                    !ks.isOnKeyRelease());
            }
            
            boolean result = super.processKeyBinding (newStroke, 
                newEvent, condition, pressed);
            
            if (newEvent.isConsumed()) {
                e.consume();
            }
            return result;
        } else if (!isAlt) {
            return super.processKeyBinding (ks, e, condition, pressed);
        } else {
            return false;
        }
    } else {
        return super.processKeyBinding (ks, e, condition, pressed);
    }                     
}