Java Code Examples for java.awt.event.KeyEvent#VK_ALT
The following examples show how to use
java.awt.event.KeyEvent#VK_ALT .
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: KeyShortCutEditPanel.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
private void textFieldKeyCodeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldKeyCodeKeyPressed if (this.buttonEditKeyCode.isSelected()){ switch(evt.getKeyCode()){ case KeyEvent.VK_META: case KeyEvent.VK_ALT: case KeyEvent.VK_SHIFT: case KeyEvent.VK_CONTROL: evt.consume();break; default:{ updateCurrentSelectedForKey(evt); this.buttonEditKeyCode.setSelected(false); this.tableKeyShortcuts.requestFocus(); }break; } } evt.consume(); }
Example 2
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 3
Source File: DeadKeyMacOSXInputText.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); char keyChar = e.getKeyChar(); switch (state) { case 0: if (keyCode != KeyEvent.VK_ALT) { throw new RuntimeException("Alt is not pressed."); } state++; break; case 1: if (keyCode != KeyEvent.VK_DEAD_ACUTE) { throw new RuntimeException("Dead ACUTE is not pressed."); } if (keyChar != 0xB4) { throw new RuntimeException("Pressed char is not dead acute."); } state++; break; } }
Example 4
Source File: DeadKeyMacOSXInputText.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); char keyChar = e.getKeyChar(); switch (state) { case 0: if (keyCode != KeyEvent.VK_ALT) { throw new RuntimeException("Alt is not pressed."); } state++; break; case 1: if (keyCode != KeyEvent.VK_DEAD_ACUTE) { throw new RuntimeException("Dead ACUTE is not pressed."); } if (keyChar != 0xB4) { throw new RuntimeException("Pressed char is not dead acute."); } state++; break; } }
Example 5
Source File: AquaMnemonicHandler.java From hottub with GNU General Public License v2.0 | 6 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 6
Source File: WindowsRootPaneUI.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public boolean postProcessKeyEvent(KeyEvent ev) { if(ev.isConsumed()) { // do not manage consumed event 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 { altKeyPressed = false; } return false; }
Example 7
Source File: PopupManager.java From netbeans with Apache License 2.0 | 5 votes |
public @Override void keyPressed(KeyEvent e){ if (e != null && popup != null && popup.isShowing()) { // get popup's registered keyboard actions ActionMap am = popup.getActionMap(); InputMap im = popup.getInputMap(); // check whether popup registers keystroke KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e); Object obj = im.get(ks); LOG.log(Level.FINE, "Keystroke for event {0}: {1}; action-map-key={2}", new Object [] { e, ks, obj }); //NOI18N if (shouldPopupReceiveForwardedKeyboardAction(obj)) { // if yes, gets the popup's action for this keystroke, perform it // and consume key event Action action = am.get(obj); LOG.log(Level.FINE, "Popup component''s action: {0}, {1}", new Object [] { action, action != null ? action.getValue(Action.NAME) : null }); //NOI18N /* Make sure to use the popup as the source of the action, since the popup is also providing the event. Not doing this, and instead invoking actionPerformed with a null ActionEvent, was one part of the problem seen in NETBEANS-403. */ if (SwingUtilities.notifyAction(action, ks, e, popup, e.getModifiers())) { e.consume(); return; } } if (e.getKeyCode() != KeyEvent.VK_CONTROL && e.getKeyCode() != KeyEvent.VK_SHIFT && e.getKeyCode() != KeyEvent.VK_ALT && e.getKeyCode() != KeyEvent.VK_ALT_GRAPH && e.getKeyCode() != KeyEvent.VK_META ) { // hide tooltip if any was shown Utilities.getEditorUI(textComponent).getToolTipSupport().setToolTipVisible(false); } } }
Example 8
Source File: EditTool.java From Logisim with GNU General Public License v3.0 | 5 votes |
@Override public void keyReleased(Canvas canvas, KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_ALT: updateLocation(canvas, e); e.consume(); break; default: select.keyReleased(canvas, e); } }
Example 9
Source File: WindowsRootPaneUI.java From JDKSourceCode1.8 with MIT License | 5 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 { altKeyPressed = false; } return false; }
Example 10
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 11
Source File: KeyboardModifierListener.java From consulo with Apache License 2.0 | 5 votes |
private void onKeyEvent(KeyEvent e) { final int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_SHIFT) { myShiftPressed = e.getID() == KeyEvent.KEY_PRESSED; onModifiersChanged(); } if (keyCode == KeyEvent.VK_CONTROL) { myCtrlPressed = e.getID() == KeyEvent.KEY_PRESSED; onModifiersChanged(); } if (keyCode == KeyEvent.VK_ALT) { myAltPressed = e.getID() == KeyEvent.KEY_PRESSED; onModifiersChanged(); } }
Example 12
Source File: WindowsRootPaneUI.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public boolean postProcessKeyEvent(KeyEvent ev) { if(ev.isConsumed()) { // do not manage consumed event 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 { altKeyPressed = false; } return false; }
Example 13
Source File: ShortcutsDialog.java From netbeans with Apache License 2.0 | 5 votes |
public void keyPressed (KeyEvent e) { KeyStroke keyStroke = ShortcutListener.createKeyStroke(e); boolean add = e.getKeyCode () != KeyEvent.VK_SHIFT && e.getKeyCode () != KeyEvent.VK_CONTROL && e.getKeyCode () != KeyEvent.VK_ALT && e.getKeyCode () != KeyEvent.VK_META && e.getKeyCode () != KeyEvent.VK_ALT_GRAPH; if (keyStroke.equals (backspaceKS) && !key.equals ("")) { // delete last key int i = key.lastIndexOf (' '); //NOI18N if (i < 0) { key = ""; //NOI18N } else { key = key.substring (0, i); } getTfShortcut().setText (key); } else { // add key addKeyStroke (keyStroke, add); } if (add) { updateWarning(); } else { setShortcutValid(false); } e.consume (); }
Example 14
Source File: KeyEventCodeToString.java From Repeat with Apache License 2.0 | 5 votes |
/** * Convert from code from KeyEvent.VK_* to a human friendly string. * This is needed because in some OSes the KeyEvent utility does * not work properly. */ public static String codeToString(int code) { switch (code) { case KeyEvent.VK_CONTROL: return "Ctrl"; case KeyEvent.VK_ALT: if (OSIdentifier.IS_OSX) { return "Option"; } return "Alt"; case KeyEvent.VK_WINDOWS: return "Windows"; case KeyEvent.VK_META: if (OSIdentifier.IS_LINUX) { return "Meta"; } if (OSIdentifier.IS_OSX) { return "Command"; } break; case KeyEvent.VK_SHIFT: return "Shift"; case KeyEvent.VK_TAB: return "Tab"; case KeyEvent.VK_SPACE: return "Space"; } return KeyEvent.getKeyText(code); }
Example 15
Source File: ImageCommand.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
public int getKeyEvent(String key) { switch (key.toUpperCase()) { case "TAB": return KeyEvent.VK_TAB; case "ENTER": return KeyEvent.VK_ENTER; case "SHIFT": return KeyEvent.VK_SHIFT; case "CTRL": return KeyEvent.VK_CONTROL; case "ALT": return KeyEvent.VK_ALT; case "START": return KeyEvent.VK_WINDOWS; case "DELETE": return KeyEvent.VK_DELETE; case "BACKSPACE": return KeyEvent.VK_BACK_SPACE; case "HOME": return KeyEvent.VK_HOME; case "PAGE_UP": case "PAGEUP": return KeyEvent.VK_PAGE_UP; case "PAGE_DOWN": case "PAGEDOWN": return KeyEvent.VK_PAGE_DOWN; case "UP": return KeyEvent.VK_UP; case "DOWN": return KeyEvent.VK_DOWN; case "LEFT": return KeyEvent.VK_LEFT; case "RIGHT": return KeyEvent.VK_RIGHT; default: return KeyEvent.VK_ESCAPE; } }
Example 16
Source File: ModifierRobotKeyTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public ModifierRobotKeyTest() throws Exception { modifierKeys = new int[4]; modifierKeys[0] = KeyEvent.VK_SHIFT; modifierKeys[1] = KeyEvent.VK_CONTROL; modifierKeys[2] = KeyEvent.VK_ALT; modifierKeys[3] = KeyEvent.VK_ALT_GRAPH; inputMasks = new int[4]; inputMasks[0] = InputEvent.SHIFT_MASK; inputMasks[1] = InputEvent.CTRL_MASK; inputMasks[2] = InputEvent.ALT_MASK; inputMasks[3] = InputEvent.ALT_GRAPH_MASK; modifierStatus = new boolean[modifierKeys.length]; textKeys = new int[2]; textKeys[0] = KeyEvent.VK_A; String os = System.getProperty("os.name").toLowerCase(); if (os.contains("solaris") || os.contains("sunos")) textKeys[1] = KeyEvent.VK_S; else if (os.contains("os x")) textKeys[1] = KeyEvent.VK_K; else textKeys[1] = KeyEvent.VK_I; textStatus = new boolean[textKeys.length]; EventQueue.invokeAndWait( () -> { initializeGUI(); }); }
Example 17
Source File: ModifierKeyDoubleClickHandler.java From consulo with Apache License 2.0 | 4 votes |
public static int getMultiCaretActionModifier() { return SystemInfo.isMac ? KeyEvent.VK_ALT : KeyEvent.VK_CONTROL; }
Example 18
Source File: DesktopToolWindowManagerImpl.java From consulo with Apache License 2.0 | 4 votes |
public boolean dispatchKeyEvent(KeyEvent e) { if (e.getKeyCode() != KeyEvent.VK_CONTROL && e.getKeyCode() != KeyEvent.VK_ALT && e.getKeyCode() != KeyEvent.VK_SHIFT && e.getKeyCode() != KeyEvent.VK_META) { if (e.getModifiers() == 0) { resetHoldState(); } return false; } if (e.getID() != KeyEvent.KEY_PRESSED && e.getID() != KeyEvent.KEY_RELEASED) return false; Component parent = UIUtil.findUltimateParent(e.getComponent()); if(parent instanceof Window) { consulo.ui.Window uiWindow = TargetAWT.from((Window)parent); IdeFrame ideFrame = uiWindow.getUserData(IdeFrame.KEY); if (ideFrame != null && ideFrame.getProject() != myProject) { resetHoldState(); return false; } } Set<Integer> vks = getActivateToolWindowVKs(); if (vks.isEmpty()) { resetHoldState(); return false; } if (vks.contains(e.getKeyCode())) { boolean pressed = e.getID() == KeyEvent.KEY_PRESSED; int modifiers = e.getModifiers(); int mouseMask = InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON3_DOWN_MASK; if ((e.getModifiersEx() & mouseMask) == 0) { if (areAllModifiersPressed(modifiers, vks) || !pressed) { processState(pressed); } else { resetHoldState(); } } } return false; }
Example 19
Source File: StaffApplication.java From RemoteSupportTool with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("Duplicates") protected synchronized void doHandleKeyRelease(KeyEvent e) { if (handler == null) return; //LOGGER.debug("key released: " + e.paramString()); // Get code of the released key. // Keypad arrows are translated to regular arrow keys. final int keyCode; switch (e.getKeyCode()) { case KeyEvent.VK_KP_DOWN: keyCode = KeyEvent.VK_DOWN; break; case KeyEvent.VK_KP_LEFT: keyCode = KeyEvent.VK_LEFT; break; case KeyEvent.VK_KP_RIGHT: keyCode = KeyEvent.VK_RIGHT; break; case KeyEvent.VK_KP_UP: keyCode = KeyEvent.VK_UP; break; default: keyCode = e.getKeyCode(); break; } // Never press undefined key codes. if (keyCode == KeyEvent.VK_UNDEFINED) { return; } // Never send caps lock, num lock and scroll lock key. if (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK || keyCode == KeyEvent.VK_SCROLL_LOCK) { return; } // Detect, if a control key was pressed. final boolean isControlKey = e.isActionKey() || keyCode == KeyEvent.VK_BACK_SPACE || keyCode == KeyEvent.VK_DELETE || keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_SPACE || keyCode == KeyEvent.VK_TAB || keyCode == KeyEvent.VK_ESCAPE || keyCode == KeyEvent.VK_ALT || keyCode == KeyEvent.VK_ALT_GRAPH || keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_META; // Release control keys. if (isControlKey) { //LOGGER.debug("release key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode)); handler.sendKeyRelease(keyCode); e.consume(); } // Release other keys, if they are pressed together with a modifier key. else if (e.isControlDown() || e.isMetaDown() || windowsKeyDown || (!SystemUtils.IS_OS_MAC && e.isAltDown()) || pressedKeys.contains(keyCode)) { //LOGGER.debug("release key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode)); handler.sendKeyRelease(keyCode); pressedKeys.remove((Integer) keyCode); e.consume(); } // Forget, that the Windows key is pressed. if (keyCode == KeyEvent.VK_WINDOWS) { synchronized (Frame.this) { windowsKeyDown = false; } } }
Example 20
Source File: OSUtils.java From marathonv5 with Apache License 2.0 | 4 votes |
public static String keyEventGetKeyText(int keycode) { if (keycode == KeyEvent.VK_TAB) { return "Tab"; } if (keycode == KeyEvent.VK_CONTROL) { return "Ctrl"; } if (keycode == KeyEvent.VK_ALT) { return "Alt"; } if (keycode == KeyEvent.VK_SHIFT) { return "Shift"; } if (keycode == KeyEvent.VK_META) { return "Meta"; } if (keycode == KeyEvent.VK_SPACE) { return "Space"; } if (keycode == KeyEvent.VK_BACK_SPACE) { return "Backspace"; } if (keycode == KeyEvent.VK_HOME) { return "Home"; } if (keycode == KeyEvent.VK_END) { return "End"; } if (keycode == KeyEvent.VK_DELETE) { return "Delete"; } if (keycode == KeyEvent.VK_PAGE_UP) { return "Pageup"; } if (keycode == KeyEvent.VK_PAGE_DOWN) { return "Pagedown"; } if (keycode == KeyEvent.VK_UP) { return "Up"; } if (keycode == KeyEvent.VK_DOWN) { return "Down"; } if (keycode == KeyEvent.VK_LEFT) { return "Left"; } if (keycode == KeyEvent.VK_RIGHT) { return "Right"; } if (keycode == KeyEvent.VK_ENTER) { return "Enter"; } return KeyEvent.getKeyText(keycode); }