Java 8 KeyEvent - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 KeyEvent class.

This code example shows how to use the following methods:getWhen, getKeyChar, getKeyCode, getKeyLocation
				return KEY_MAP[key_code];
		} 
	} 
 
	public void keyPressed(KeyEvent e) {
		handleKey(e.getKeyCode(), e.getKeyLocation(), (byte)1, e.getKeyChar(), e.getWhen()*1000000);
	} 
 
	public void keyReleased(KeyEvent e) {
		handleKey(e.getKeyCode(), e.getKeyLocation(), (byte)0, Keyboard.CHAR_NONE, e.getWhen()*1000000);
	} 
 
	public void keyTyped(KeyEvent e) {
	} 
} 
7
CodeRank
This code example shows how to use the following methods:getID, getModifiers, getWhen, getKeyChar, getKeyCode
	public boolean dispatchKeyEvent(final KeyEvent ke) {
		if(ke.equals(dispatchedEvent)){
			return false; 
		} 
		if(textComponent != null){
			KeyEvent newEvent = new KeyEvent(textComponent, ke.getID(), ke.getWhen(), ke.getModifiers(), ke.getKeyCode(), ke.getKeyChar(), ke.getKeyLocation());
			events.add(newEvent);
		} 
        else { 
	        events.add(ke);
        } 
		 
		// Prevent Freeplane freeze 
		if(ke.getKeyCode() == KeyEvent.VK_ESCAPE 
				&& ke.getID() == KeyEvent.KEY_RELEASED){
			EventQueue.invokeLater(new Runnable() {
				public void run() { 
					KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(EventBuffer.this);
				} 
			}); 
6
CodeRank
This code example shows how to use the following methods:getWhen, isAltDown, isControlDown, isMetaDown, getKeyChar
	 * focus to the next object that starts with the same letter until another 
	 * key is pressed, then it is treated as the prefix with appropriate number 
	 * of the same letters followed by first typed anothe letter. 
	 */ 
	public void keyTyped(KeyEvent e) {
	    LimeJTable src = (LimeJTable)e.getSource();
	    TableModel model = src.getModel();
	     
        if (model.getRowCount() == 0 ||
          e.isAltDown() || e.isControlDown() || e.isMetaDown() ||
	      isNavigationKey(e)) {
            // Nothing to select 
            return; 
        } 
         
	    boolean startingFromSelection = true;
	    char c = e.getKeyChar();
	    long time = e.getWhen();
	    int startIndex = src.getSelectionModel().getLeadSelectionIndex();
	     

6
CodeRank
This code example shows how to use the following methods:isAltDown, isShiftDown, getKeyCode, getSource
 
		// use event.isAltDown rather than AppD.isControlDown(event) 
		// as we need to distinguish <AltGr>2 and <Ctrl>2 
		// #2390 #908 
		return handleGeneralKeys( 
				KeyCodes.translateJavacode(event.getKeyCode()),
				event.isShiftDown(), AppD.isControlDown(event),
				event.isAltDown(), event.getSource() instanceof JTable,
				event.getSource() instanceof EuclidianViewD);
	} 
 
	private boolean handleSelectedGeosKeys(KeyEvent event,
			ArrayList<GeoElement> geos) {
 
		// use event.isAltDown rather than AppD.isAltDown(event) 
		// as Ctrl-Arrow on OSX does something special 
		// so we actually want to use Alt 
		return handleSelectedGeosKeys( 
				KeyCodes.translateJavacode(event.getKeyCode()), geos,
				event.isShiftDown(), AppD.isControlDown(event),

6
CodeRank
This code example shows how to use the following methods:getID, getModifiersEx, getWhen, getKeyChar, getKeyCode
	public void mouseWheelMoved(MouseWheelEvent e) {
		handleInteractiveEvent(new MouseWheelMovedEvent(mirroredMouseWheelEvent(e)));
	} 
 
	public static KeyEvent cloneKeyEvent(final KeyEvent e) {
		return new KeyEvent(SafeComponent.getSafeEventComponent(), e.getID(), e.getWhen(), e.getModifiersEx(),
				e.getKeyCode(), e.getKeyChar(), e.getKeyLocation());
	} 
 
	private void handleInteractiveEvent(robocode.Event event) {
		battleManager.sendInteractiveEvent(event);
	} 
 
	private MouseEvent mirroredMouseEvent(final MouseEvent e) {
 
		double scale;
		BattleProperties battleProps = battleManager.getBattleProperties();
 
		int vWidth = battleView.getWidth();
		int vHeight = battleView.getHeight();
7
CodeRank
This code example shows how to use the following methods:consume, getWhen, getKeyCode
		} 
	} 
 
	@Override 
	public void keyPressed(KeyEvent e) {
		int keyCode = e.getKeyCode();
		System.out.println("keyPressed " + keyCode + " " + e.getWhen());
 
		if (keyCode == KeyEvent.VK_LEFT) {
			left = true;
			leftLastChangeMs = System.currentTimeMillis();
		} else if (keyCode == KeyEvent.VK_RIGHT) {
			right = true;
			rightLastChangeMs = System.currentTimeMillis();
		} else if (keyCode == KeyEvent.VK_UP) {
			forward = true;
			forwardLastChangeMs = System.currentTimeMillis();
		} else if (keyCode == KeyEvent.VK_DOWN) {
			reverse = true;
			reverseLastChangeMs = System.currentTimeMillis();

6
CodeRank
This code example shows how to use the following methods:getModifiers, getModifiersEx, getKeyCode
     * @param e event 
     * @param k keystroke 
     * @return true if event matches the keystroke definition 
     */ 
    public static boolean matches(KeyEvent e, KeyStroke k){
        final int modifiersEx = e.getModifiersEx()  | e.getModifiers();// Hack to get full modifier value
        return e.getKeyCode() == k.getKeyCode() && modifiersEx == k.getModifiers();
    } 
} 
6
CodeRank
This code example shows how to use the following methods:isConsumed
    } 
 
    public synchronized void keyReleased(final KeyEvent e) {
        pressed = false;
        keyReleased++;
        if(e.isConsumed()) {
            consumed++;
        } 
        queue.add(e);
        if( verbose ) {
            System.err.println("KEY AWT RELEASED ["+pressed+"]: "+prefix+", "+e);
        } 
    } 
 
    public String toString() { return prefix+"[pressed "+pressed+", keyReleased "+keyReleased+", consumed "+consumed+"]"; }
} 
 
6
CodeRank
This code example shows how to use the following methods:getModifiers, getWhen, getKeyChar, getKeyCode
				  mev.isPopupTrigger());
	} 
 
	if(evt instanceof KeyEvent) {
	    KeyEvent kev=(KeyEvent)evt;
	    return new KeyEvent(src, evt.getID(), kev.getWhen(), kev.getModifiers(), 
				kev.getKeyCode(), kev.getKeyChar());
	} 
 
	if(evt instanceof ActionEvent)
	    return new ActionEvent(src, evt.getID(), ((ActionEvent)evt).getActionCommand(),
				   ((ActionEvent)evt).getModifiers());
 
 
	if(evt instanceof PaintEvent)
	    return new PaintEvent(src, evt.getID(), ((PaintEvent)evt).getUpdateRect());
 
 
	if(evt instanceof FocusEvent)
	    return new FocusEvent(src, evt.getID(), ((FocusEvent)evt).isTemporary());
6
CodeRank
This code example shows how to use the following methods:getID, consume, getModifiers, getKeyChar, getKeyCode
	 * {@link KeyEventWorkaround#processKeyEvent(java.awt.event.KeyEvent)}. 
	 *  
	 * @since jEdit 4.2pre3 
	 */ 
	public static Key translateKeyEvent(final KeyEvent evt) {
		final int modifiers = evt.getModifiers();
		Key returnValue = null;
		switch (evt.getID()) {
			case KeyEvent.KEY_PRESSED:
				final int keyCode = evt.getKeyCode();
				if ((keyCode >= KeyEvent.VK_0 && keyCode <= KeyEvent.VK_9)
				        || (keyCode >= KeyEvent.VK_A && keyCode <= KeyEvent.VK_Z)) {
					returnValue = new Key(KeyEventTranslator.modifiersToString(modifiers), '\0', Character
					    .toUpperCase((char) keyCode));
				} 
				else { 
					if (keyCode > 0 && keyCode <= KeyEvent.VK_SPACE
							|| keyCode == KeyEvent.VK_DELETE) {
						evt.consume();
						returnValue = new Key(KeyEventTranslator.modifiersToString(modifiers), keyCode,

6
CodeRank
See Code Examples for Java 8 KeyEvent Methods: