Java Code Examples for java.awt.event.KeyEvent#getKeyCode()
The following examples show how to use
java.awt.event.KeyEvent#getKeyCode() .
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: Ruler.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 8 votes |
@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
Source File: AquaMnemonicHandler.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 8 votes |
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 File: MainPanel.java From javagame with MIT License | 8 votes |
/** * �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 File: MenuItem.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@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 5
Source File: Utilities.java From wpcleaner with Apache License 2.0 | 6 votes |
/** * 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 6
Source File: TraitScreen.java From open-ig with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean keyboard(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { e.consume(); cancel.onClick.invoke(); return true; } return false; }
Example 7
Source File: BaselineCorrectorSetupDialog.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
@Override public void keyPressed(KeyEvent ke) { int keyCode = ke.getKeyCode(); if (keyCode == KeyEvent.VK_ESCAPE) { LOG.info("<ESC> Presssed."); previewTask.kill(); hidePreview(); } }
Example 8
Source File: XButtonPeer.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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 9
Source File: DQC.java From javagame with MIT License | 5 votes |
/** * �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 10
Source File: MainPanel.java From javagame with MIT License | 5 votes |
/** * �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 11
Source File: CAbstractTreeTable.java From binnavi with Apache License 2.0 | 5 votes |
@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 File: MarkAllFoundAction.java From otroslogviewer with Apache License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == 10 && KeyEvent.CTRL_MASK == e.getModifiers()) { actionPerformed(new ActionEvent(e.getSource(), e.getID(), "")); } }
Example 13
Source File: Search.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
public void keyPressed(KeyEvent ke) { if (ke.getKeyCode() == KeyEvent.VK_ENTER) { executeSearch(); return; } tryCloseTab(ke); }
Example 14
Source File: ShortcutOptionsPanel.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * 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 15
Source File: frmImportPoints.java From Course_Generator with GNU General Public License v3.0 | 5 votes |
/** * 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 16
Source File: PhotoEditorPanel.java From mvisc with GNU General Public License v3.0 | 4 votes |
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 17
Source File: KeyManager.java From New-Beginner-Java-Game-Programming-Src with Creative Commons Zero v1.0 Universal | 4 votes |
@Override public void keyReleased(KeyEvent e) { if(e.getKeyCode() < 0 || e.getKeyCode() >= keys.length) return; keys[e.getKeyCode()] = false; }
Example 18
Source File: FindPanel.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { find(); } }
Example 19
Source File: StyledEditor.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 4 votes |
private static boolean isFormat(KeyEvent ke) { return ke.isShiftDown() && ke.getKeyCode() == KeyEvent.VK_F; }
Example 20
Source File: Keyboard.java From Cherno with GNU General Public License v3.0 | 4 votes |
public void keyReleased(KeyEvent e) { keys[e.getKeyCode()] = false; if (pressed.contains(new Integer(e.getKeyCode()))) pressed.remove(new Integer(e.getKeyCode())); }