Java Code Examples for java.awt.event.KeyEvent#VK_TAB
The following examples show how to use
java.awt.event.KeyEvent#VK_TAB .
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: Keys.java From SikuliNG with MIT License | 8 votes |
public static boolean isRepeatable(String token) { int key = toJavaKeyCodeFromText(token); switch (key) { case KeyEvent.VK_UP: return true; case KeyEvent.VK_DOWN: return true; case KeyEvent.VK_RIGHT: return true; case KeyEvent.VK_LEFT: return true; case -KeyEvent.VK_TAB: return true; case KeyEvent.VK_TAB: return true; case KeyEvent.VK_ENTER: return true; case KeyEvent.VK_BACK_SPACE: return true; } return false; }
Example 2
Source File: PGrammarPaneTest.java From PolyGlot with MIT License | 6 votes |
@Test public void testProcessKeyEvent() { boolean success = true; String errorMessage = ""; System.out.println("PGrammarPaneTest.testPasteTabSanitize"); try { PGrammarPane pane = new PGrammarPane(core); KeyEvent testEvent = new KeyEvent(pane, 0, 1L, 0, KeyEvent.VK_TAB, ' '); pane.processKeyEvent(testEvent); } catch (Exception e) { errorMessage = e.getLocalizedMessage(); IOHandler.writeErrorLog(e, errorMessage); success = false; } assertTrue(success, errorMessage); }
Example 3
Source File: GameWindow.java From dungeon with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Handles a key press in the text field. This method checks for a command history access by the keys UP, DOWN, or TAB * and, if this is the case, processes this query. * * @param event the KeyEvent. */ private void textFieldKeyPressed(KeyEvent event) { int keyCode = event.getKeyCode(); if (isUpDownOrTab(keyCode)) { // Check if the event is of interest. GameState gameState = Game.getGameState(); if (gameState != null) { CommandHistory commandHistory = gameState.getCommandHistory(); if (keyCode == KeyEvent.VK_UP) { textField.setText(commandHistory.getCursor().moveUp().getSelectedCommand()); } else if (keyCode == KeyEvent.VK_DOWN) { textField.setText(commandHistory.getCursor().moveDown().getSelectedCommand()); } else if (keyCode == KeyEvent.VK_TAB) { // Using the empty String to get the last similar command will always retrieve the last command. // Therefore, there is no need to check if there is something in the text field. String lastSimilarCommand = commandHistory.getLastSimilarCommand(getTrimmedTextFieldText()); if (lastSimilarCommand != null) { textField.setText(lastSimilarCommand); } } } } }
Example 4
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 5
Source File: DirectoryChooserUI.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent evt) { showPopupCompletion = true; int keyCode = evt.getKeyCode(); // #105801: completionPopup might not be ready when updateCompletions not called (empty text field) if (completionPopup != null && !completionPopup.isVisible()) { if (keyCode == KeyEvent.VK_ENTER) { File file = getFileChooser().getFileSystemView().createFileObject(filenameTextField.getText()); if(file.exists() && file.isDirectory()) { setSelected(new File[] {file}); fileChooser.approveSelection(); if (file.getParentFile() == null) { // this will hopefully prevent popup to take inappropriate action evt.consume(); } } } if ((keyCode == KeyEvent.VK_TAB || keyCode == KeyEvent.VK_DOWN) || (keyCode == KeyEvent.VK_RIGHT && (filenameTextField.getCaretPosition() >= (filenameTextField.getDocument().getLength() - 1)))) { updateCompletions(); } } if(filenameTextField.isFocusOwner() && (completionPopup == null || !completionPopup.isVisible()) && keyCode == KeyEvent.VK_ESCAPE) { fileChooser.cancelSelection(); } }
Example 6
Source File: NavBarItem.java From consulo with Apache License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_TAB) { // Check source is a nav bar item if (e.getSource() instanceof NavBarItem) { e.consume(); jumpToNextComponent(!e.isShiftDown()); } } }
Example 7
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 8
Source File: Key.java From SikuliX1 with MIT License | 5 votes |
public static boolean isRepeatable(String token) { int key = toJavaKeyCodeFromText(token); switch (key) { case KeyEvent.VK_UP: return true; case KeyEvent.VK_DOWN: return true; case KeyEvent.VK_RIGHT: return true; case KeyEvent.VK_LEFT: return true; case -KeyEvent.VK_TAB: return true; case KeyEvent.VK_TAB: return true; case KeyEvent.VK_ENTER: return true; case KeyEvent.VK_BACK_SPACE: return true; } return false; }
Example 9
Source File: CustomizerRun.java From netbeans with Apache License 2.0 | 5 votes |
private void jTextVMOptionsKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextVMOptionsKeyPressed if (evt.getKeyCode() == KeyEvent.VK_ENTER) { evt.consume(); } if (evt.getKeyCode() == KeyEvent.VK_TAB) { if (evt.getModifiers() > 0) { jTextVMOptions.transferFocusBackward(); } else { jTextVMOptions.transferFocus(); } evt.consume(); } }
Example 10
Source File: CycleFocusAction.java From netbeans with Apache License 2.0 | 5 votes |
public State keyTyped (Widget widget, WidgetKeyEvent event) { boolean state = false; if (event.getKeyChar () == KeyEvent.VK_TAB) { if ((event.getModifiers () & KeyEvent.SHIFT_MASK) == KeyEvent.SHIFT_MASK) state = provider.switchPreviousFocus (widget); else state = provider.switchNextFocus (widget); } return state ? State.CONSUMED : State.REJECTED; }
Example 11
Source File: Popup.java From MeteoInfo with GNU Lesser General Public License v3.0 | 4 votes |
public synchronized void type(KeyEvent e) { if (!this.isVisible()) return; switch (e.getKeyCode()) { case KeyEvent.VK_ESCAPE: this.setVisible(false); break; case KeyEvent.VK_ENTER: case KeyEvent.VK_TAB: this.chooseSelected(); e.consume(); break; case KeyEvent.VK_SPACE: this.chooseSelected(); break; case KeyEvent.VK_PERIOD: this.chooseSelected(); break; case KeyEvent.VK_LEFT_PARENTHESIS: this.chooseSelected(); break; case KeyEvent.VK_UP: this.up(); e.consume(); break; case KeyEvent.VK_DOWN: this.down(); e.consume(); break; case KeyEvent.VK_PAGE_UP: this.pageUp(); e.consume(); break; case KeyEvent.VK_PAGE_DOWN: this.pageDown(); e.consume(); break; case KeyEvent.VK_BACK_SPACE: if (this.typed.isEmpty()){ this.setVisible(false); break; } this.typed = this.typed.substring(0, this.typed.length() - 1); this.data = filter(this.originalData, this.typed); this.list.setListData(this.data); this.list.setSelectedIndex(0); break; default: char c = e.getKeyChar(); if (Character.isJavaIdentifierPart(c)){ this.typed += c; this.data = filter(this.data, this.typed); this.list.setListData(this.data); this.list.setSelectedIndex(0); } break; } }
Example 12
Source File: ChatboxItemSearch.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void keyPressed(KeyEvent ev) { switch (ev.getKeyCode()) { case KeyEvent.VK_ENTER: ev.consume(); if (index > -1) { if (onItemSelected != null) { onItemSelected.accept(results.keySet().toArray(new Integer[results.size()])[index]); } chatboxPanelManager.close(); } break; case KeyEvent.VK_TAB: case KeyEvent.VK_RIGHT: ev.consume(); if (!results.isEmpty()) { index++; if (index >= results.size()) { index = 0; } clientThread.invokeLater(this::update); } break; case KeyEvent.VK_LEFT: ev.consume(); if (!results.isEmpty()) { index--; if (index < 0) { index = results.size() - 1; } clientThread.invokeLater(this::update); } break; case KeyEvent.VK_UP: ev.consume(); if (results.size() >= (MAX_RESULTS / 2)) { index -= MAX_RESULTS / 2; if (index < 0) { if (results.size() == MAX_RESULTS) { index += results.size(); } else { index += MAX_RESULTS; } index = Ints.constrainToRange(index, 0, results.size() - 1); } clientThread.invokeLater(this::update); } break; case KeyEvent.VK_DOWN: ev.consume(); if (results.size() >= (MAX_RESULTS / 2)) { index += MAX_RESULTS / 2; if (index >= MAX_RESULTS) { if (results.size() == MAX_RESULTS) { index -= results.size(); } else { index -= MAX_RESULTS; } index = Ints.constrainToRange(index, 0, results.size() - 1); } clientThread.invokeLater(this::update); } break; default: super.keyPressed(ev); } }
Example 13
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 14
Source File: GameWindow.java From dungeon with BSD 3-Clause "New" or "Revised" License | 4 votes |
private boolean isUpDownOrTab(int keyCode) { return keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_TAB; }
Example 15
Source File: StaffApplication.java From RemoteSupportTool with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("Duplicates") protected synchronized void doHandleKeyPress(KeyEvent e) { if (handler == null) return; //LOGGER.debug("key pressed: " + e.paramString()); // Get code of the pressed 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; // Press control keys. if (isControlKey) { //LOGGER.debug("press key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode)); handler.sendKeyPress(keyCode); e.consume(); } // Press other keys, if they are pressed together with a modifier key. else if (e.isControlDown() || e.isMetaDown() || windowsKeyDown || (!SystemUtils.IS_OS_MAC && e.isAltDown())) { //LOGGER.debug("press key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode)); handler.sendKeyPress(keyCode); if (!pressedKeys.contains(keyCode)) pressedKeys.add(keyCode); e.consume(); } // Remember, that the Windows key was pressed. if (keyCode == KeyEvent.VK_WINDOWS) { synchronized (Frame.this) { windowsKeyDown = true; } } }
Example 16
Source File: CDefaultLabelEventHandler.java From binnavi with Apache License 2.0 | 4 votes |
@Override public void keyPressed(final KeyEvent event) { if (!isActive()) { return; } if (event.getKeyCode() == KeyEvent.VK_ESCAPE) { deactivateLabelContent(); return; } if ((event.getKeyCode() == KeyEvent.VK_TAB) && (event.getModifiers() != 0) && (event.getModifiers() != InputEvent.SHIFT_DOWN_MASK)) { return; } if (!getActiveLabelContent().isSelectable()) { return; } CAbstractKeyBehavior behaviour = null; final char keyText = KeyEvent.getKeyText(event.getKeyCode()).charAt(0); if (event.isControlDown() && (keyText >= 'A') && (keyText <= 'Z')) { behaviour = m_ctrlKeyBehaviourMap.get(event.getKeyCode()); } if (behaviour == null) { behaviour = m_keyBehaviourMap.get(event.getKeyCode()); if ((behaviour == null) && (event.getKeyChar() != KeyEvent.CHAR_UNDEFINED) && !event.isControlDown() && getActiveLabelContent().isEditable()) { behaviour = m_keyBehaviourMap.get(null); } } if (behaviour != null) { int y = -1; String oldContent = ""; if (getActiveLabelContent().isEditable()) { y = getActiveLabelContent().getCaret().getYmouseReleased(); oldContent = getContentSnippet(y); } behaviour.keyPressed(getActiveLabelContent(), event); if (y > -1) { final String newContent = getContentSnippet(y); if (!oldContent.equals(newContent) && !oldContent.isEmpty()) { for (final ILabelEditableContentListener listener : m_editModeListener) { listener.editableContentChanged(getActiveLabelContent()); } } } m_activeRealizer.regenerate(); m_activeRealizer.repaint(); m_graph.updateViews(); } event.consume(); }
Example 17
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); }
Example 18
Source File: KeyboardHandler.java From rscplus with GNU General Public License v3.0 | 4 votes |
@Override public void keyReleased(KeyEvent e) { if (Replay.isRecording) { Replay.dumpKeyboardInput( e.getKeyCode(), Replay.KEYBOARD_RELEASED, e.getKeyChar(), e.getModifiers()); } // Reset dialogue option if (dialogue_option >= 0 && !Replay.isPlaying) { dialogue_option = -1; e.consume(); } if (e.getKeyCode() == KeyEvent.VK_TAB) e.consume(); // Handle camera keys if (!e.isConsumed()) { if (e.getKeyCode() == KeyEvent.VK_LEFT) { keyLeft = false; if (Settings.CAMERA_ROTATABLE.get(Settings.currentProfile)) e.consume(); } if (e.getKeyCode() == KeyEvent.VK_RIGHT) { keyRight = false; if (Settings.CAMERA_ROTATABLE.get(Settings.currentProfile)) e.consume(); } if (e.getKeyCode() == KeyEvent.VK_UP) { keyUp = false; if (Settings.CAMERA_ZOOMABLE.get(Settings.currentProfile)) e.consume(); } if (e.getKeyCode() == KeyEvent.VK_DOWN) { keyDown = false; if (Settings.CAMERA_ZOOMABLE.get(Settings.currentProfile)) e.consume(); } keyShift = e.isShiftDown(); } if (listener_key != null && !e.isConsumed()) { listener_key.keyReleased(e); } }
Example 19
Source File: KeyCodeToChar.java From Repeat with Apache License 2.0 | 4 votes |
private static String getNonAlphaCharWithShift(int code) { switch (code) { case KeyEvent.VK_BACK_QUOTE: return "~"; case KeyEvent.VK_1: return "!"; case KeyEvent.VK_2: return "@"; case KeyEvent.VK_3: return "#"; case KeyEvent.VK_4: return "$"; case KeyEvent.VK_5: return "%"; case KeyEvent.VK_6: return "^"; case KeyEvent.VK_7: return "&"; case KeyEvent.VK_8: return "*"; case KeyEvent.VK_9: return "("; case KeyEvent.VK_0: return ")"; case KeyEvent.VK_MINUS: return "_"; case KeyEvent.VK_EQUALS: return "+"; case KeyEvent.VK_OPEN_BRACKET: return "{"; case KeyEvent.VK_CLOSE_BRACKET: return "}"; case KeyEvent.VK_SEMICOLON: return ":"; case KeyEvent.VK_QUOTE: return "\""; case KeyEvent.VK_BACK_SLASH: return "|"; case KeyEvent.VK_COMMA: return "<"; case KeyEvent.VK_PERIOD: return ">"; case KeyEvent.VK_SLASH: return "?"; case KeyEvent.VK_TAB: return "\t"; case KeyEvent.VK_ENTER: return "\n"; case KeyEvent.VK_SPACE: return " "; default: return ""; } }
Example 20
Source File: AWTConsole.java From beanshell with Apache License 2.0 | 4 votes |
public void type(int code, char ch, int modifiers ) { switch ( code ) { case KeyEvent.VK_BACK_SPACE: if (line.length() > 0) { line.setLength( line.length() - 1 ); replaceRange( "", textLength-1, textLength ); textLength--; } break; case KeyEvent.VK_ENTER: enter(); break; case KeyEvent.VK_U: if ( (modifiers & InputEvent.CTRL_DOWN_MASK) > 0 ) { int len = line.length(); replaceRange( "", textLength-len, textLength ); line.setLength( 0 ); histLine = 0; textLength = getText().length(); } else doChar( ch ); break; case KeyEvent.VK_UP: historyUp(); break; case KeyEvent.VK_DOWN: historyDown(); break; case KeyEvent.VK_TAB: line.append(" "); append(" "); textLength +=4; break; /* case KeyEvent.VK_LEFT: if (line.length() > 0) { break; */ // Control-C case KeyEvent.VK_C: if ( (modifiers & InputEvent.CTRL_DOWN_MASK) > 0 ) { line.append("^C"); append("^C"); textLength += 2; } else doChar( ch ); break; default: doChar( ch ); } }