Java Code Examples for java.awt.event.KeyEvent#VK_CANCEL
The following examples show how to use
java.awt.event.KeyEvent#VK_CANCEL .
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: KeyStrokeParser.java From marathonv5 with Apache License 2.0 | 5 votes |
public static String getTextForKeyChar(char keyChar) { int keycode; switch (keyChar) { case ' ': keycode = KeyEvent.VK_SPACE; break; case '\b': keycode = KeyEvent.VK_BACK_SPACE; break; case '\t': keycode = KeyEvent.VK_TAB; break; case '\n': keycode = KeyEvent.VK_ENTER; break; case '\u0018': keycode = KeyEvent.VK_CANCEL; break; case '\u001b': keycode = KeyEvent.VK_ESCAPE; break; case '\u007f': keycode = KeyEvent.VK_DELETE; break; default: return "" + keyChar; } return (String) keyCodes.get(Integer.valueOf(keycode)); }
Example 2
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 3
Source File: ShortcutAndMenuKeyEventProcessor.java From netbeans with Apache License 2.0 | 4 votes |
public boolean dispatchKeyEvent(KeyEvent ev) { log.fine("dispatchKeyEvent ev: " + ev.paramString() + " source:" + ev.getSource().getClass().getName()); // in some ctx, may need event filtering if (NbKeymap.getContext().length != 0) { // Ignore anything but KeyPressed inside ctx, #67187 if (ev.getID() != KeyEvent.KEY_PRESSED) { ev.consume(); return true; } skipNextTyped = true; Component comp = ev.getComponent(); if (!(comp instanceof JComponent) || ((JComponent)comp).getClientProperty("context-api-aware") == null) { // not context api aware, don't pass subsequent events processShortcut(ev); // ignore processShortcut result, consume everything while in ctx return true; } } if (ev.getID() == KeyEvent.KEY_PRESSED && ev.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK) && (ev.getKeyCode() == KeyEvent.VK_PAUSE || ev.getKeyCode() == KeyEvent.VK_CANCEL) ) { Object source = ev.getSource(); if (source instanceof Component) { Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); System.err.println("*** ShortcutAndMenuKeyEventProcessor: current focus owner = " + focused); // NOI18N } ev.consume(); return true; } // multi-shortcut in middle if (ev.getID() == KeyEvent.KEY_TYPED && skipNextTyped) { ev.consume(); skipNextTyped = false; return true; } if (ev.getID() == KeyEvent.KEY_RELEASED) { skipNextTyped = false; } if (ev.getID() == KeyEvent.KEY_PRESSED) { // decompose to primitive fields to avoid memory profiler confusion (keyEvent keeps source reference) lastKeyChar = ev.getKeyChar(); lastModifiers = ev.getModifiers(); lastSampled = true; } MenuElement[] arr = MenuSelectionManager.defaultManager().getSelectedPath(); if (arr == null || arr.length == 0) { wasPopupDisplayed = false; // Only here for fix #41477: // To be able to catch and dispatch Ctrl+TAB and Ctrl+Shift+Tab // in our own way, it's needed to do as soon as here, because // otherwise Swing will use these keys as focus traversals, which // means that TopComponent which contains focusCycleRoot inside itself // will grab these shortcuts, which is not desirable return KeyboardPopupSwitcher.processShortcut(ev); } if (!wasPopupDisplayed && lastSampled == true && ev.getID() == KeyEvent.KEY_TYPED && lastModifiers == InputEvent.ALT_MASK && ev.getModifiers() == InputEvent.ALT_MASK && lastKeyChar == ev.getKeyChar() ) { wasPopupDisplayed = true; ev.consume(); return true; } wasPopupDisplayed = true; MenuSelectionManager.defaultManager().processKeyEvent(ev); // commented out as #130919 fix - I don't know why this was here, but // it did prevent keyboard functioning in menus in dialogs /*if (!ev.isConsumed() && arr != null && arr.length > 0 && arr[0] instanceof JMenuBar) { ev.setSource(WindowManagerImpl.getInstance().getMainWindow()); }*/ return ev.isConsumed(); }
Example 4
Source File: TextFieldCaret.java From Logisim with GNU General Public License v3.0 | 4 votes |
@Override public void keyPressed(KeyEvent e) { int ign = InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.META_DOWN_MASK; if ((e.getModifiersEx() & ign) != 0) return; switch (e.getKeyCode()) { case KeyEvent.VK_LEFT: case KeyEvent.VK_KP_LEFT: if (pos > 0) --pos; break; case KeyEvent.VK_RIGHT: case KeyEvent.VK_KP_RIGHT: if (pos < curText.length()) ++pos; break; case KeyEvent.VK_HOME: pos = 0; break; case KeyEvent.VK_END: pos = curText.length(); break; case KeyEvent.VK_ESCAPE: case KeyEvent.VK_CANCEL: cancelEditing(); break; case KeyEvent.VK_CLEAR: curText = ""; pos = 0; break; case KeyEvent.VK_ENTER: stopEditing(); break; case KeyEvent.VK_BACK_SPACE: if (pos > 0) { curText = curText.substring(0, pos - 1) + curText.substring(pos); --pos; field.setText(curText); } break; case KeyEvent.VK_DELETE: if (pos < curText.length()) { curText = curText.substring(0, pos) + curText.substring(pos + 1); field.setText(curText); } break; case KeyEvent.VK_INSERT: case KeyEvent.VK_COPY: case KeyEvent.VK_CUT: case KeyEvent.VK_PASTE: // TODO: enhance label editing break; default: ; // ignore } }