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

The following examples show how to use java.awt.event.KeyEvent#getKeyCode() . These examples are extracted from open source projects. 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
@Override
public void keyPressed(KeyEvent e) {
    int step = e.isControlDown() ? 50 : e.isAltDown() ? 1 : 5;
    switch (e.getKeyCode()) {
        case KeyEvent.VK_LEFT:
            setLocation(getX() - step, getY());
            break;
        case KeyEvent.VK_RIGHT:
            setLocation(getX() + step, getY());
            break;
        case KeyEvent.VK_UP:
            setLocation(getX(), getY() - step);
            break;
        case KeyEvent.VK_DOWN:
            setLocation(getX(), getY() + step);
            break;
        case KeyEvent.VK_ESCAPE:
            exitAction.actionPerformed(null);
    }
}
 
Example 2
public boolean postProcessKeyEvent(final KeyEvent ev) {
    if (ev.getKeyCode() != KeyEvent.VK_ALT) {
        return false;
    }

    final JRootPane root = SwingUtilities.getRootPane(ev.getComponent());
    final Window winAncestor = (root == null ? null : SwingUtilities.getWindowAncestor(root));

    switch(ev.getID()) {
        case KeyEvent.KEY_PRESSED:
            setMnemonicHidden(false);
            break;
        case KeyEvent.KEY_RELEASED:
            setMnemonicHidden(true);
            break;
    }

    repaintMnemonicsInWindow(winAncestor);

    return false;
}
 
Example 3
Source Project: javagame   File: MainPanel.java    License: MIT License 8 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyPressed(KeyEvent e) {
    int keyCode = e.getKeyCode();

    if (keyCode == KeyEvent.VK_LEFT) {
        leftKey.press();
    }
    if (keyCode == KeyEvent.VK_RIGHT) {
        rightKey.press();
    }
    if (keyCode == KeyEvent.VK_UP) {
        upKey.press();
    }
    if (keyCode == KeyEvent.VK_DOWN) {
        downKey.press();
    }
}
 
Example 4
Source Project: wpcleaner   File: Utilities.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Listener for KeyPressed events.
 * 
 * @param e Event.
 * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
 */
@Override
public void keyPressed(KeyEvent e) {
  if ((e.getKeyCode() == KeyEvent.VK_V) &&
      ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0)) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable clipData = clipboard.getContents(clipboard);
    try {
      String s = (String) clipData.getTransferData(DataFlavor.stringFlavor);
      int start = text.getSelectionStart();
      int end = text.getSelectionEnd();
      if (end > start) {
        text.getDocument().remove(start, end - start);
      }
      text.getDocument().insertString(start, s, null);
      e.consume();
    } catch (Exception ex) {
      //
    }
  }
}
 
Example 5
@SuppressWarnings("deprecation")
boolean handleShortcut(KeyEvent e) {
    MenuShortcut s = new MenuShortcut(e.getKeyCode(),
                         (e.getModifiers() & InputEvent.SHIFT_MASK) > 0);
    MenuShortcut sE = new MenuShortcut(e.getExtendedKeyCode(),
                         (e.getModifiers() & InputEvent.SHIFT_MASK) > 0);
    // Fix For 6185151: Menu shortcuts of all menuitems within a menu
    // should be disabled when the menu itself is disabled
    if ((s.equals(shortcut) || sE.equals(shortcut)) && isItemEnabled()) {
        // MenuShortcut match -- issue an event on keydown.
        if (e.getID() == KeyEvent.KEY_PRESSED) {
            doMenuEvent(e.getWhen(), e.getModifiers());
        } else {
            // silently eat key release.
        }
        return true;
    }
    return false;
}
 
Example 6
@Override
public boolean keyboard(KeyEvent e) {
	if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
		e.consume();
		cancel.onClick.invoke();
		return true;
	}
	return false;
}
 
Example 7
/**
 * Table key release managment SPACE key invert the selection
 * 
 * @param evt event
 */
protected void TableKeyReleased(KeyEvent evt) {
	if (list.data.size() <= 0)
		return;

	int row = TableImport.getSelectedRow();
	int col = TableImport.getSelectedColumn();

	if ((col == 0) && (evt.getKeyCode() == KeyEvent.VK_SPACE)) {
		list.data.get(row).invSel();
		RefreshTable();
	}
}
 
Example 8
Source Project: wpcleaner   File: ShortcutOptionsPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Action triggered when keyboard is used.
 * 
 * @param e Event.
 * @return True if processing should end.
 * @see java.awt.KeyEventDispatcher#dispatchKeyEvent(java.awt.event.KeyEvent)
 */
@Override
public boolean dispatchKeyEvent(KeyEvent e) {
  int key = e.getKeyCode();
  if ((key == KeyEvent.VK_ALT) ||
      (key == KeyEvent.VK_ALT_GRAPH) ||
      (key == KeyEvent.VK_BACK_SPACE) ||
      (key == KeyEvent.VK_BEGIN) ||
      (key == KeyEvent.VK_CANCEL) ||
      (key == KeyEvent.VK_CAPS_LOCK) ||
      (key == KeyEvent.VK_CONTROL) ||
      (key == KeyEvent.VK_DELETE) ||
      (key == KeyEvent.VK_DOWN) ||
      (key == KeyEvent.VK_END) ||
      (key == KeyEvent.VK_ENTER) ||
      (key == KeyEvent.VK_LEFT) ||
      (key == KeyEvent.VK_PAGE_DOWN) ||
      (key == KeyEvent.VK_PAGE_UP) ||
      (key == KeyEvent.VK_RIGHT) ||
      (key == KeyEvent.VK_SHIFT) ||
      (key == KeyEvent.VK_TAB) ||
      (key == KeyEvent.VK_UP) ||
      (key == KeyEvent.VK_SHIFT)) {
    return false;
  }
  if (key != KeyEvent.VK_ESCAPE) {
    setKeyCode(key);
  }
  showNotice(false);
  KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(this);
  return false;
}
 
Example 9
Source Project: TrakEM2   File: Search.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void keyPressed(KeyEvent ke) {
	if (ke.getKeyCode() == KeyEvent.VK_ENTER) {
		executeSearch();
		return;
	}
	tryCloseTab(ke);
}
 
Example 10
@Override
public void keyPressed(KeyEvent e) {
  if (e.getKeyCode() == 10 && KeyEvent.CTRL_MASK == e.getModifiers()) {
    actionPerformed(new ActionEvent(e.getSource(), e.getID(), ""));
  }

}
 
Example 11
Source Project: binnavi   File: CAbstractTreeTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected boolean processKeyBinding(final KeyStroke keyStroke, final KeyEvent event,
    final int condition, final boolean pressed) {
  // turn off edit but still can cause actions
  if (event.getKeyCode() == KeyEvent.VK_DELETE) {
    putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);
    final boolean retvalue = super.processKeyBinding(keyStroke, event, condition, pressed);
    putClientProperty("JTable.autoStartsEdit", Boolean.TRUE);

    return retvalue;
  }

  return super.processKeyBinding(keyStroke, event, condition, pressed);
}
 
Example 12
Source Project: javagame   File: MainPanel.java    License: MIT License 5 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyReleased(KeyEvent e) {
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_LEFT) {
        leftPressed = false;
    }
    if (key == KeyEvent.VK_RIGHT) {
        rightPressed = false;
    }
    if (key == KeyEvent.VK_UP) {
        upPressed = false;
    }
}
 
Example 13
Source Project: javagame   File: DQC.java    License: MIT License 5 votes vote down vote up
/**
 * �L�[�������ꂽ�Ƃ��̏���
 * 
 */
public void keyReleased(KeyEvent e) {
    int keyCode = e.getKeyCode();

    anyKey.release();
    
    switch (keyCode) {
        case KeyEvent.VK_DOWN :
            downKey.release();
            break;
        case KeyEvent.VK_UP :
            upKey.release();
            break;
        case KeyEvent.VK_LEFT :
            leftKey.release();
            break;
        case KeyEvent.VK_RIGHT :
            rightKey.release();
            break;
        case KeyEvent.VK_SPACE:
            spaceKey.release();
            break;
        case KeyEvent.VK_T:
            talkKey.release();
            break;
        case KeyEvent.VK_S:
            searchKey.release();
            break;
        case KeyEvent.VK_O:
            openKey.release();
            break;
        case KeyEvent.VK_ESCAPE :
            System.exit(0);
    }
}
 
Example 14
void handleJavaKeyEvent(KeyEvent e) {
    int id = e.getID();
    switch (id) {
      case KeyEvent.KEY_PRESSED:
          if (e.getKeyCode() == KeyEvent.VK_SPACE)
          {
              pressed=true;
              armed=true;
              repaint();
              action(e.getWhen(),e.getModifiers());
          }

          break;

      case KeyEvent.KEY_RELEASED:
          if (e.getKeyCode() == KeyEvent.VK_SPACE)
          {
              pressed = false;
              armed = false;
              repaint();
          }

          break;


    }
}
 
Example 15
@Override
public void keyPressed(KeyEvent ke) {

  int keyCode = ke.getKeyCode();
  if (keyCode == KeyEvent.VK_ESCAPE) {

    LOG.info("<ESC> Presssed.");
    previewTask.kill();
    hidePreview();

  }
}
 
Example 16
private static boolean isFormat(KeyEvent ke) {
    return ke.isShiftDown() && ke.getKeyCode() == KeyEvent.VK_F;
}
 
Example 17
Source Project: jdk8u60   File: FindPanel.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        find();
    }
}
 
Example 18
@Override
public void keyReleased(KeyEvent e) {
	if(e.getKeyCode() < 0 || e.getKeyCode() >= keys.length)
		return;
	keys[e.getKeyCode()] = false;
}
 
Example 19
public void keyReleased(KeyEvent e)
		{
			
			copyMade = false;
			if (e.getKeyCode() == KeyEvent.VK_SPACE)
			{
//				System.out.println("k:"+selected);

				selected = !selected;
				System.out.println("hit space" + selected);
				unsavedChange = true;
				repaint();
			}
			if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
			{
				selected = false;
				repaint();
			}
			if (e.getKeyCode() == KeyEvent.VK_SHIFT)
			{
				shiftDown = false;
			}
			if (e.getKeyCode() == KeyEvent.VK_CONTROL)
			{
				controlDown = false;
			}
			if ((e.getKeyCode() == KeyEvent.VK_PLUS) || (e.getKeyCode() == KeyEvent.VK_ADD))
			{
				contrast++;
				repaint();
				copyMade = false;
			}
			if ((e.getKeyCode() == KeyEvent.VK_MINUS) || (e.getKeyCode() == KeyEvent.VK_SUBTRACT))
			{
				contrast--;
				repaint();
				copyMade = false;
			}
			if (e.getKeyCode() == KeyEvent.VK_MULTIPLY)
			{
				blur = !blur;
				repaint();
				copyMade = false;
			}

		}
 
Example 20
Source Project: Cherno   File: Keyboard.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void keyReleased(KeyEvent e) {
	keys[e.getKeyCode()] = false;
	if (pressed.contains(new Integer(e.getKeyCode()))) pressed.remove(new Integer(e.getKeyCode()));
}