Java Code Examples for java.awt.event.KeyEvent#isActionKey()
The following examples show how to use
java.awt.event.KeyEvent#isActionKey() .
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: CodeDisplayModelExample.java From binnavi with Apache License 2.0 | 6 votes |
@Override public void keyPressedOrTyped(CodeDisplayCoordinate coordinate, KeyEvent event) { if (!event.isActionKey()) { switch (event.getKeyCode()) { case KeyEvent.VK_ENTER: break; default: String stringToEdit = data.get(coordinate.getRow()).get(coordinate.getColumn()).get(coordinate.getLine()); if (stringToEdit.length() < coordinate.getFieldIndex()) { stringToEdit = padRight(stringToEdit, coordinate.getFieldIndex()); } String newString = stringToEdit.substring(0, coordinate.getFieldIndex()) + event.getKeyChar() + stringToEdit.substring(coordinate.getFieldIndex()); data.get(coordinate.getRow()).get(coordinate.getColumn()) .set(coordinate.getLine(), newString); coordinate.setFieldIndex(coordinate.getFieldIndex() + 1); break; } } else { switch (event.getKeyCode()) { case KeyEvent.VK_DOWN: break; case KeyEvent.VK_UP: break; case KeyEvent.VK_LEFT: coordinate.setFieldIndex(coordinate.getFieldIndex() - 1); break; case KeyEvent.VK_RIGHT: coordinate.setFieldIndex(coordinate.getFieldIndex() + 1); break; } } }
Example 2
Source File: FilterTextField.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
private void updateFilter(KeyEvent e) { String filterText = getText(); // do nothing if no actual change was done if (valueLastUpdate != null && valueLastUpdate.equals(filterText)) { return; } if ((filterText == null) || (filterText.length() == 0)) { if ((e == null) || ((e.getKeyCode() != KeyEvent.VK_BACK_SPACE) && (e.getKeyCode() != KeyEvent.VK_DELETE) && (e.getKeyCode() != KeyEvent.VK_SHIFT) && (e.getKeyCode() != KeyEvent.VK_ALT) && (e.getKeyCode() != KeyEvent.VK_ALT_GRAPH) && (e.getKeyCode() != KeyEvent.VK_CONTROL) && (e.getKeyCode() != KeyEvent.VK_META) && (!e.isActionKey()))) { setText(null); } } // store text when listeners were notified valueLastUpdate = filterText; for (FilterListener l : filterListeners) { l.valueChanged(filterText); } }
Example 3
Source File: KeyGetter.java From tn5250j with GNU General Public License v2.0 | 5 votes |
void processVTKeyPressed(KeyEvent e){ displayInfo(e); int keyCode = e.getKeyCode(); if (isLinux && keyCode == KeyEvent.VK_ALT_GRAPH) { isAltGr = true; } // be careful with the control key if (keyCode == KeyEvent.VK_UNDEFINED || keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_ALT || keyCode == KeyEvent.VK_ALT_GRAPH || keyCode == KeyEvent.VK_CONTROL ) { return; } // be careful with the control key !!!!!! if (!e.isAltDown() || !e.isShiftDown() || !e.isControlDown() || keyCode != KeyEvent.VK_CONTROL && // be careful about removing this line !e.isActionKey()) { // if (keyCode == KeyEvent.VK_ESCAPE || // keyCode == KeyEvent.VK_CONTROL || // keyCode == KeyEvent.VK_BACK_SPACE) { // displayInfo(e,"Pressed added"); keyevent = e; dialog.setVisible(false); dialog.dispose(); // } } }
Example 4
Source File: WSRecorder.java From marathonv5 with Apache License 2.0 | 5 votes |
@Override public void recordRawKeyEvent(RComponent r, KeyEvent e) { JSONObject event = new JSONObject(); event.put("type", "key_raw"); int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_META || keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_ALT || keyCode == KeyEvent.VK_CONTROL) { return; } if ((e.isActionKey() || e.isControlDown() || e.isMetaDown() || e.isAltDown()) && e.getID() == KeyEvent.KEY_PRESSED) { String mtext = buildModifiersText(e); event.put("modifiersEx", mtext); KeysMap keysMap = KeysMap.findMap(e.getKeyCode()); if (keysMap == KeysMap.NULL) { return; } String keyText; if (keysMap == null) { keyText = KeyEvent.getKeyText(e.getKeyCode()); } else { keyText = keysMap.toString(); } event.put("keyCode", keyText); } else if (e.getID() == KeyEvent.KEY_TYPED && !e.isControlDown()) { if (Character.isISOControl(e.getKeyChar()) && hasMapping(e.getKeyChar())) { event.put("keyChar", getMapping(e.getKeyChar())); } else { event.put("keyChar", "" + e.getKeyChar()); } } else { return; } recordEvent(r, event); }
Example 5
Source File: AbstractDockingTest.java From ghidra with Apache License 2.0 | 5 votes |
public static void triggerKey(Component c, int modifiers, int keyCode, char keyChar, BiConsumer<Component, KeyEvent> consumer) { Objects.requireNonNull(c); Objects.requireNonNull(consumer); if (c instanceof JTextComponent) { JTextComponent tf = (JTextComponent) c; forceTextComponentFocus(tf); } KeyEvent pressedKE = new KeyEvent(c, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), modifiers, keyCode, keyChar); consumer.accept(c, pressedKE); if (!pressedKE.isActionKey()) { // action keys are keys like the function (F1) keys char updatedKeyChar = (keyChar == KeyEvent.CHAR_UNDEFINED) ? (char) keyCode : keyChar; KeyEvent typedKE = new KeyEvent(c, KeyEvent.KEY_TYPED, System.currentTimeMillis(), modifiers, KeyEvent.VK_UNDEFINED, updatedKeyChar); consumer.accept(c, typedKE); } KeyEvent releasedKE = new KeyEvent(c, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), modifiers, keyCode, keyChar); consumer.accept(c, releasedKE); }
Example 6
Source File: AutoLookup.java From ghidra with Apache License 2.0 | 5 votes |
private boolean isIgnorableKeyEvent(KeyEvent event) { // ignore modified keys, except for SHIFT if (!isUnmodifiedOrShift(event.getModifiersEx())) { return true; } if (event.isActionKey() || event.getKeyChar() == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(event.getKeyChar())) { return true; } return false; }
Example 7
Source File: AutomaticTextField.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
@Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE || e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { e.consume(); } else if (!e.isActionKey()) { this.mainText = this.getText(); generatePopup(true); this.requestFocus(); } }
Example 8
Source File: DefaultKeyboardFocusManager.java From TencentKona-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 9
Source File: DefaultKeyboardFocusManager.java From jdk-1.7-annotated with Apache License 2.0 | 4 votes |
private void consumeTraversalKey(KeyEvent e) { e.consume(); consumeNextKeyTyped = (e.getID() == KeyEvent.KEY_PRESSED) && !e.isActionKey(); }
Example 10
Source File: JPanel_FileBrowser.java From MobyDroid with Apache License 2.0 | 4 votes |
@Override public void keyReleased(KeyEvent ke) { // check for change in text if (!documentUpdated || ke.isActionKey()) { return; } // get written newText String newText = ((JTextField) ke.getSource()).getText(); // is it really changed? if (newText.equals(jComboBox_Path_String)) { return; } else { jComboBox_Path_String = newText; } // start working if (newText.isEmpty()) { // hide popup jComboBox.hidePopup(); // set default model jComboBox.setModel(defaultModel); // set newText ((JTextField) jComboBox.getEditor().getEditorComponent()).setText(newText); } else { // clear old suggestions Model suggestionModel.removeAllElements(); // iterate over all items for (int ii = 0; ii < defaultModel.getSize(); ii++) { Object currentItem = defaultModel.getElementAt(ii); // current item starts with the pattern? if (currentItem != null && currentItem.toString().toLowerCase().startsWith(newText.toLowerCase())) { suggestionModel.addElement(currentItem.toString()); } } if (suggestionModel.getSize() == 0) { // hide popup jComboBox.hidePopup(); // set new model jComboBox.setModel(suggestionModel); // set newText ((JTextField) jComboBox.getEditor().getEditorComponent()).setText(newText); } else { // hide popup jComboBox.hidePopup(); // set new model jComboBox.setModel(suggestionModel); // set newText ((JTextField) jComboBox.getEditor().getEditorComponent()).setText(newText); // set selected index //jComboBox_URL.setSelectedIndex(-1); // show popup jComboBox.showPopup(); } } documentUpdated = false; }
Example 11
Source File: DefaultKeyboardFocusManager.java From jdk8u-jdk 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 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: 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 14
Source File: AutoCompleteDecorator.java From cropplanning with GNU General Public License v3.0 | 4 votes |
/** * Enables automatic completion for the given JComboBox. The automatic * completion will be strict (only items from the combo box can be selected) * if the combo box is not editable. * @param comboBox a combo box * @param stringConverter the converter used to transform items to strings */ public static void decorate(final JComboBox comboBox, final ObjectToStringConverter stringConverter) { boolean strictMatching = !comboBox.isEditable(); // has to be editable comboBox.setEditable(true); // fix the popup location AquaLnFPopupLocationFix.install(comboBox); // configure the text component=editor component JTextComponent editorComponent = (JTextComponent) comboBox.getEditor().getEditorComponent(); final AbstractAutoCompleteAdaptor adaptor = new ComboBoxAdaptor(comboBox); final AutoCompleteDocument document = new AutoCompleteDocument(adaptor, strictMatching, stringConverter); decorate(editorComponent, document, adaptor); // show the popup list when the user presses a key final KeyListener keyListener = new KeyAdapter() { public void keyPressed(KeyEvent keyEvent) { // don't popup on action keys (cursor movements, etc...) if (keyEvent.isActionKey()) return; // don't popup if the combobox isn't visible anyway if (comboBox.isDisplayable() && !comboBox.isPopupVisible()) { int keyCode = keyEvent.getKeyCode(); // don't popup when the user hits shift,ctrl or alt if (keyCode==keyEvent.VK_SHIFT || keyCode==keyEvent.VK_CONTROL || keyCode==keyEvent.VK_ALT) return; // don't popup when the user hits escape (see issue #311) if (keyCode==keyEvent.VK_ESCAPE) return; comboBox.setPopupVisible(true); } } }; editorComponent.addKeyListener(keyListener); if (stringConverter!=ObjectToStringConverter.DEFAULT_IMPLEMENTATION) { comboBox.setEditor(new AutoCompleteComboBoxEditor(comboBox.getEditor(), stringConverter)); } // Changing the l&f can change the combobox' editor which in turn // would not be autocompletion-enabled. The new editor needs to be set-up. comboBox.addPropertyChangeListener("editor", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { ComboBoxEditor editor = (ComboBoxEditor) e.getNewValue(); if (editor!=null && editor.getEditorComponent()!=null) { if (!(editor instanceof AutoCompleteComboBoxEditor) && stringConverter!=ObjectToStringConverter.DEFAULT_IMPLEMENTATION) { comboBox.setEditor(new AutoCompleteComboBoxEditor(editor, stringConverter)); // Don't do the decorate step here because calling setEditor will trigger // the propertychange listener a second time, which will do the decorate // and addKeyListener step. } else { decorate((JTextComponent) editor.getEditorComponent(), document, adaptor); editor.getEditorComponent().addKeyListener(keyListener); } } } }); }
Example 15
Source File: DefaultKeyboardFocusManager.java From Bytecoder with Apache License 2.0 | 4 votes |
private void consumeTraversalKey(KeyEvent e) { e.consume(); consumeNextKeyTyped = (e.getID() == KeyEvent.KEY_PRESSED) && !e.isActionKey(); }
Example 16
Source File: DefaultKeyboardFocusManager.java From openjdk-jdk9 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 17
Source File: DefaultKeyboardFocusManager.java From jdk8u-jdk 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 18
Source File: DefaultInputHandler.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
/** * Handle a key pressed event. This will look up the binding for the key stroke and execute it. */ @Override @SuppressWarnings("unchecked") public void keyPressed(KeyEvent evt) { int keyCode = evt.getKeyCode(); int modifiers = evt.getModifiers(); if (keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_ALT || keyCode == KeyEvent.VK_META) { return; } if ((modifiers & InputEvent.SHIFT_MASK) != 0 || (modifiers & InputEvent.CTRL_MASK) != 0 || evt.isActionKey() || keyCode == KeyEvent.VK_BACK_SPACE || keyCode == KeyEvent.VK_DELETE || keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB || keyCode == KeyEvent.VK_ESCAPE) { if (grabAction != null) { handleGrabAction(evt); return; } KeyStroke keyStroke = KeyStroke.getKeyStroke(keyCode, modifiers); Object o = currentBindings.get(keyStroke); if (o == null) { // Don't beep if the user presses some // key we don't know about unless a // prefix is active. Otherwise it will // beep when caps lock is pressed, etc. if (currentBindings != bindings) { Toolkit.getDefaultToolkit().beep(); // F10 should be passed on, but C+e F10 // shouldn't repeatCount = 0; repeat = false; evt.consume(); } currentBindings = bindings; return; } else if (o instanceof ActionListener) { currentBindings = bindings; executeAction((ActionListener) o, evt.getSource(), null); evt.consume(); return; } else if (o instanceof Hashtable) { currentBindings = (Hashtable<KeyStroke, Object>) o; evt.consume(); return; } } }
Example 19
Source File: DefaultKeyboardFocusManager.java From hottub 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 20
Source File: DefaultKeyboardFocusManager.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private void consumeTraversalKey(KeyEvent e) { e.consume(); consumeNextKeyTyped = (e.getID() == KeyEvent.KEY_PRESSED) && !e.isActionKey(); }