Java Code Examples for java.awt.event.KeyEvent#KEY_PRESSED
The following examples show how to use
java.awt.event.KeyEvent#KEY_PRESSED .
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: MenuBar.java From openjdk-jdk8u with GNU General Public License v2.0 | 8 votes |
boolean handleShortcut(KeyEvent e) { // Is it a key event? int id = e.getID(); if (id != KeyEvent.KEY_PRESSED && id != KeyEvent.KEY_RELEASED) { return false; } // Is the accelerator modifier key pressed? int accelKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); if ((e.getModifiers() & accelKey) == 0) { return false; } // Pass MenuShortcut on to child menus. int nmenus = getMenuCount(); for (int i = 0 ; i < nmenus ; i++) { Menu m = getMenu(i); if (m.handleShortcut(e)) { return true; } } return false; }
Example 2
Source File: MenuBar.java From hottub with GNU General Public License v2.0 | 6 votes |
boolean handleShortcut(KeyEvent e) { // Is it a key event? int id = e.getID(); if (id != KeyEvent.KEY_PRESSED && id != KeyEvent.KEY_RELEASED) { return false; } // Is the accelerator modifier key pressed? int accelKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); if ((e.getModifiers() & accelKey) == 0) { return false; } // Pass MenuShortcut on to child menus. int nmenus = getMenuCount(); for (int i = 0 ; i < nmenus ; i++) { Menu m = getMenu(i); if (m.handleShortcut(e)) { return true; } } return false; }
Example 3
Source File: ShortcutTextField.java From consulo with Apache License 2.0 | 6 votes |
@Override protected void processKeyEvent(KeyEvent e) { if (e.getID() == KeyEvent.KEY_PRESSED) { int keyCode = e.getKeyCode(); if ( keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_ALT || keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_ALT_GRAPH || keyCode == KeyEvent.VK_META ){ return; } setKeyStroke(KeyStrokeAdapter.getDefaultKeyStroke(e)); } }
Example 4
Source File: GUILabelingTool.java From Pixie with MIT License | 6 votes |
/** * Handles the keys which have the same functionality for all the types * of labeling. */ private void dispatchKeyGeneral(KeyEvent e) { int eventId = e.getID(); int key = e.getKeyCode(); // the mapping of the keys is based on the default assignment of keys for UGEE graphic tablet if (eventId == KeyEvent.KEY_PRESSED) { if (e.isControlDown()) { handleCtrlKey(key); } else if (e.isAltDown()) { handleAltKey(key); } else { handleNormalKey(key); } } }
Example 5
Source File: MenuBar.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
boolean handleShortcut(KeyEvent e) { // Is it a key event? int id = e.getID(); if (id != KeyEvent.KEY_PRESSED && id != KeyEvent.KEY_RELEASED) { return false; } // Is the accelerator modifier key pressed? int accelKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); if ((e.getModifiers() & accelKey) == 0) { return false; } // Pass MenuShortcut on to child menus. int nmenus = getMenuCount(); for (int i = 0 ; i < nmenus ; i++) { Menu m = getMenu(i); if (m.handleShortcut(e)) { return true; } } return false; }
Example 6
Source File: CommandDispatcher.java From IBC with GNU General Public License v3.0 | 5 votes |
private void handleReconnectAccountCommand() { JFrame jf = MainWindowManager.mainWindowManager().getMainWindow(); int modifiers = KeyEvent.CTRL_DOWN_MASK | KeyEvent.ALT_DOWN_MASK; KeyEvent pressed=new KeyEvent(jf, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), modifiers, KeyEvent.VK_R, KeyEvent.CHAR_UNDEFINED); KeyEvent typed=new KeyEvent(jf, KeyEvent.KEY_TYPED, System.currentTimeMillis(), modifiers, KeyEvent.VK_UNDEFINED, 'R' ); KeyEvent released=new KeyEvent(jf, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), modifiers, KeyEvent.VK_R, KeyEvent.CHAR_UNDEFINED ); jf.dispatchEvent(pressed); jf.dispatchEvent(typed); jf.dispatchEvent(released); mChannel.writeAck(""); }
Example 7
Source File: XButtonPeer.java From TencentKona-8 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 8
Source File: XButtonPeer.java From jdk8u-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: RComponent.java From marathonv5 with Apache License 2.0 | 5 votes |
public void processEvent(AWTEvent event) { setIndexOfType(super.getIndexOfType()); if (event instanceof MouseEvent) { MouseEvent me = (MouseEvent) event; switch (me.getID()) { case MouseEvent.MOUSE_ENTERED: mouseEntered(me); break; case MouseEvent.MOUSE_PRESSED: mousePressed(me); break; case MouseEvent.MOUSE_RELEASED: mouseReleased(me); break; case MouseEvent.MOUSE_CLICKED: mouseClicked(me); break; case MouseEvent.MOUSE_EXITED: mouseExited(me); break; } } else if (event instanceof KeyEvent) { KeyEvent ke = (KeyEvent) event; switch (ke.getID()) { case KeyEvent.KEY_PRESSED: keyPressed(ke); break; case KeyEvent.KEY_RELEASED: keyReleased(ke); break; case KeyEvent.KEY_TYPED: keyTyped(ke); break; } } }
Example 10
Source File: KeyboardHandler.java From tn5250j with GNU General Public License v2.0 | 5 votes |
/** * Utility method, calls one of <code>keyPressed()</code>, * <code>keyReleased()</code>, or <code>keyTyped()</code>. */ public void processKeyEvent(KeyEvent evt) { switch(evt.getID()) { case KeyEvent.KEY_TYPED: keyTyped(evt); break; case KeyEvent.KEY_PRESSED: keyPressed(evt); break; case KeyEvent.KEY_RELEASED: keyReleased(evt); break; } }
Example 11
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 12
Source File: BaseTable.java From netbeans with Apache License 2.0 | 4 votes |
/** Overridden to allow standard keybinding processing of VK_TAB and * abort any pending drag operation on the vertical grid. */ public void processKeyEvent(KeyEvent e) { if (dragListener.isArmed()) { dragListener.setArmed(false); } boolean suppressDefaultHandling = ((searchField != null) && searchField.isShowing()) && ((e.getKeyCode() == KeyEvent.VK_UP) || (e.getKeyCode() == KeyEvent.VK_DOWN)); //Manually hook in the bindings for tab - does not seem to get called //automatically if (e.getKeyCode() != KeyEvent.VK_TAB) { if (!suppressDefaultHandling) { //Either the search field or the table should handle up/down, not both super.processKeyEvent(e); } if (!e.isConsumed()) { if ((e.getID() == KeyEvent.KEY_PRESSED) && !isEditing()) { int modifiers = e.getModifiers(); int keyCode = e.getKeyCode(); if (((modifiers > 0) && (modifiers != KeyEvent.SHIFT_MASK)) || e.isActionKey()) { return; } char c = e.getKeyChar(); if (!Character.isISOControl(c) && (keyCode != KeyEvent.VK_SHIFT) && (keyCode != KeyEvent.VK_ESCAPE)) { searchArmed = true; e.consume(); } } else if (searchArmed && (e.getID() == KeyEvent.KEY_TYPED)) { passToSearchField(e); e.consume(); searchArmed = false; } else { searchArmed = false; } } } else { processKeyBinding( KeyStroke.getKeyStroke(e.VK_TAB, e.getModifiersEx(), e.getID() == e.KEY_RELEASED), e, JComponent.WHEN_FOCUSED, e.getID() == e.KEY_PRESSED ); } }
Example 13
Source File: DefaultKeyboardFocusManager.java From JDKSourceCode1.8 with MIT License | 4 votes |
private void consumeTraversalKey(KeyEvent e) { e.consume(); consumeNextKeyTyped = (e.getID() == KeyEvent.KEY_PRESSED) && !e.isActionKey(); }
Example 14
Source File: InstantRenamePerformerTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testCancel6() throws Exception { KeyEvent ke = new KeyEvent(new JFrame(), KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_DELETE, '\0'); performTest("package test; public class Test { public void test() {int x|xx = 0; int y = xxx; } }", 84 - 22 - 1, ke, "package test; public class Test { public void test() {int xxx= 0; int y = xxx; } }", false); }
Example 15
Source File: DefaultKeyboardFocusManager.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private void consumeTraversalKey(KeyEvent e) { e.consume(); consumeNextKeyTyped = (e.getID() == KeyEvent.KEY_PRESSED) && !e.isActionKey(); }
Example 16
Source File: WindowsRootPaneUI.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public boolean postProcessKeyEvent(KeyEvent ev) { if(ev.isConsumed() && ev.getKeyCode() != KeyEvent.VK_ALT) { // mnemonic combination, it's consumed, but we need // set altKeyPressed to false, otherwise after selection // component by mnemonic combination a menu will be open altKeyPressed = false; return false; } if (ev.getKeyCode() == KeyEvent.VK_ALT) { root = SwingUtilities.getRootPane(ev.getComponent()); winAncestor = (root == null ? null : SwingUtilities.getWindowAncestor(root)); if (ev.getID() == KeyEvent.KEY_PRESSED) { if (!altKeyPressed) { altPressed(ev); } altKeyPressed = true; return true; } else if (ev.getID() == KeyEvent.KEY_RELEASED) { if (altKeyPressed) { altReleased(ev); } else { MenuSelectionManager msm = MenuSelectionManager.defaultManager(); MenuElement[] path = msm.getSelectedPath(); if (path.length <= 0) { WindowsLookAndFeel.setMnemonicHidden(true); WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor); } } altKeyPressed = false; } root = null; winAncestor = null; } else { if (WindowsLookAndFeel.isMnemonicHidden() && ev.isAltDown()) { WindowsLookAndFeel.setMnemonicHidden(false); WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor); } altKeyPressed = false; } return false; }
Example 17
Source File: KeyboardDnd.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void eventDispatched( AWTEvent e ) { if( !(e instanceof KeyEvent) ) return; KeyEvent ke = ( KeyEvent ) e; ke.consume(); if( e.getID() == KeyEvent.KEY_PRESSED ) { switch( ke.getKeyCode() ) { case KeyEvent.VK_LEFT: do { currentSide = currentSide.moveLeft(); } while( !checkDropLocation() ); refresh(); break; case KeyEvent.VK_RIGHT: do { currentSide = currentSide.moveRight(); } while( !checkDropLocation() ); refresh(); break; case KeyEvent.VK_UP: do { currentSide = currentSide.moveUp(); } while( !checkDropLocation() ); refresh(); break; case KeyEvent.VK_DOWN: do { currentSide = currentSide.moveDown(); } while( !checkDropLocation() ); refresh(); break; case KeyEvent.VK_ENTER: stop( true ); break; case KeyEvent.VK_ESCAPE: abort(); break; } } }
Example 18
Source File: TimeUI.java From whyline with MIT License | 4 votes |
public boolean ioEventIsOfDesiredType(IOEvent io) { if(selection == null) return true; if(io instanceof MouseStateInputEvent) { MouseStateInputEvent mouseEvent = (MouseStateInputEvent)io; int id = mouseEvent.getType(); switch(id) { case MouseEvent.MOUSE_PRESSED : return selection == press; case MouseEvent.MOUSE_DRAGGED : return selection == drag; case MouseEvent.MOUSE_CLICKED : case MouseEvent.MOUSE_RELEASED : return selection == release; case MouseEvent.MOUSE_WHEEL : return selection == scroll; case MouseEvent.MOUSE_MOVED : return selection == move; default : return false; } } else if(io instanceof KeyStateInputEvent) { KeyStateInputEvent keyEvent = (KeyStateInputEvent)io; int type = keyEvent.getType(); switch(type) { case KeyEvent.KEY_PRESSED : return selection == keydown; case KeyEvent.KEY_RELEASED : return selection == keyup; case KeyEvent.KEY_TYPED : return selection == keyup; default: return false; } } else if(selection == repaint) return io instanceof GetGraphicsOutputEvent; else if(selection == print) return io instanceof TextualOutputEvent; else return false; }
Example 19
Source File: DefaultKeyboardFocusManager.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * This method initiates a focus traversal operation if and only if the * KeyEvent represents a focus traversal key for the specified * focusedComponent. It is expected that focusedComponent is the current * focus owner, although this need not be the case. If it is not, * focus traversal will nevertheless proceed as if focusedComponent * were the focus owner. * * @param focusedComponent the Component that is the basis for a focus * traversal operation if the specified event represents a focus * traversal key for the Component * @param e the event that may represent a focus traversal key */ public void processKeyEvent(Component focusedComponent, KeyEvent e) { // consume processed event if needed if (consumeProcessedKeyEvent(e)) { return; } // KEY_TYPED events cannot be focus traversal keys if (e.getID() == KeyEvent.KEY_TYPED) { return; } if (focusedComponent.getFocusTraversalKeysEnabled() && !e.isConsumed()) { AWTKeyStroke stroke = AWTKeyStroke.getAWTKeyStrokeForEvent(e), oppStroke = AWTKeyStroke.getAWTKeyStroke(stroke.getKeyCode(), stroke.getModifiers(), !stroke.isOnKeyRelease()); Set<AWTKeyStroke> toTest; boolean contains, containsOpp; toTest = focusedComponent.getFocusTraversalKeys( KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); contains = toTest.contains(stroke); containsOpp = toTest.contains(oppStroke); if (contains || containsOpp) { consumeTraversalKey(e); if (contains) { focusNextComponent(focusedComponent); } return; } else if (e.getID() == KeyEvent.KEY_PRESSED) { // Fix for 6637607: consumeNextKeyTyped should be reset. consumeNextKeyTyped = false; } toTest = focusedComponent.getFocusTraversalKeys( KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); contains = toTest.contains(stroke); containsOpp = toTest.contains(oppStroke); if (contains || containsOpp) { consumeTraversalKey(e); if (contains) { focusPreviousComponent(focusedComponent); } return; } toTest = focusedComponent.getFocusTraversalKeys( KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS); contains = toTest.contains(stroke); containsOpp = toTest.contains(oppStroke); if (contains || containsOpp) { consumeTraversalKey(e); if (contains) { upFocusCycle(focusedComponent); } return; } if (!((focusedComponent instanceof Container) && ((Container)focusedComponent).isFocusCycleRoot())) { return; } toTest = focusedComponent.getFocusTraversalKeys( KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS); contains = toTest.contains(stroke); containsOpp = toTest.contains(oppStroke); if (contains || containsOpp) { consumeTraversalKey(e); if (contains) { downFocusCycle((Container)focusedComponent); } } } }
Example 20
Source File: InputContext.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * @see java.awt.im.InputContext#dispatchEvent */ @SuppressWarnings("fallthrough") public void dispatchEvent(AWTEvent event) { if (event instanceof InputMethodEvent) { return; } // Ignore focus events that relate to the InputMethodWindow of this context. // This is a workaround. Should be removed after 4452384 is fixed. if (event instanceof FocusEvent) { Component opposite = ((FocusEvent)event).getOppositeComponent(); if ((opposite != null) && (getComponentWindow(opposite) instanceof InputMethodWindow) && (opposite.getInputContext() == this)) { return; } } InputMethod inputMethod = getInputMethod(); int id = event.getID(); switch (id) { case FocusEvent.FOCUS_GAINED: focusGained((Component) event.getSource()); break; case FocusEvent.FOCUS_LOST: focusLost((Component) event.getSource(), ((FocusEvent) event).isTemporary()); break; case KeyEvent.KEY_PRESSED: if (checkInputMethodSelectionKey((KeyEvent)event)) { // pop up the input method selection menu InputMethodManager.getInstance().notifyChangeRequestByHotKey((Component)event.getSource()); break; } // fall through default: if ((inputMethod != null) && (event instanceof InputEvent)) { inputMethod.dispatchEvent(event); } } }