Java Code Examples for java.awt.event.KeyEvent#getKeyChar()
The following examples show how to use
java.awt.event.KeyEvent#getKeyChar() .
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: GenericCommentsTableModel.java From binnavi with Apache License 2.0 | 6 votes |
private IComment handleRegularKeyInComment(IComment comment, CodeDisplayCoordinate coordinate, KeyEvent event) { int line = coordinate.getLine(); int field = coordinate.getFieldIndex(); int commentIndex = lineAndIndexToCommentIndex(comment, line, field); if (commentIndex >= 0) { comment = insertStringIntoComment(comment, line, field, "" + event.getKeyChar()); } else { String lineString = comment.getCommentLine(coordinate.getLine()); String paddingAndKey = CodeDisplay.padRight("", coordinate.getFieldIndex() - lineString.length()) + event.getKeyChar(); comment = insertStringIntoComment(comment, coordinate.getLine(), lineString.length(), paddingAndKey); } return comment; }
Example 2
Source File: CompletionSupport.java From netbeans with Apache License 2.0 | 6 votes |
public void processKeyEvent (KeyEvent evt) { if (evt.getID() == KeyEvent.KEY_TYPED) { char c = evt.getKeyChar(); JTextComponent component = (JTextComponent)evt.getSource(); if (confirmChars == null) { confirmChars = getConfirmChars(component); } if (confirmChars.indexOf(c) != -1) { if (c != '.') { Completion.get().hideDocumentation(); Completion.get().hideCompletion(); } NbEditorDocument doc = (NbEditorDocument) component.getDocument (); try { defaultAction(component); doc.insertString(processKeyEventOffset, Character.toString(c), null); } catch (BadLocationException e) { } if (c == '.') Completion.get().showCompletion(); evt.consume(); } // if } // if }
Example 3
Source File: DeadKeyMacOSXInputText.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public void keyTyped(KeyEvent e) { int keyCode = e.getKeyCode(); char keyChar = e.getKeyChar(); if (state == 2) { if (keyCode != 0) { throw new RuntimeException("Key code should be undefined."); } if (keyChar != 0xE1) { throw new RuntimeException("A char does not have ACCUTE accent"); } state++; } else { throw new RuntimeException("Wron number of keyTyped events."); } }
Example 4
Source File: DeadKeyMacOSXInputText.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@Override public void keyTyped(KeyEvent e) { int keyCode = e.getKeyCode(); char keyChar = e.getKeyChar(); if (state == 2) { if (keyCode != 0) { throw new RuntimeException("Key code should be undefined."); } if (keyChar != 0xE1) { throw new RuntimeException("A char does not have ACCUTE accent"); } state++; } else { throw new RuntimeException("Wron number of keyTyped events."); } }
Example 5
Source File: DeadKeyMacOSXInputText.java From hottub with GNU General Public License v2.0 | 6 votes |
@Override public void keyTyped(KeyEvent e) { int keyCode = e.getKeyCode(); char keyChar = e.getKeyChar(); if (state == 2) { if (keyCode != 0) { throw new RuntimeException("Key code should be undefined."); } if (keyChar != 0xE1) { throw new RuntimeException("A char does not have ACCUTE accent"); } state++; } else { throw new RuntimeException("Wron number of keyTyped events."); } }
Example 6
Source File: DeadKeyMacOSXInputText.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public void keyTyped(KeyEvent e) { int keyCode = e.getKeyCode(); char keyChar = e.getKeyChar(); if (state == 2) { if (keyCode != 0) { throw new RuntimeException("Key code should be undefined."); } if (keyChar != 0xE1) { throw new RuntimeException("A char does not have ACCUTE accent"); } state++; } else { throw new RuntimeException("Wron number of keyTyped events."); } }
Example 7
Source File: JavaTypeCompletionItem.java From nb-springboot with Apache License 2.0 | 6 votes |
@Override public void processKeyEvent(KeyEvent evt) { if (evt.getID() == KeyEvent.KEY_TYPED && evt.getKeyChar() == '.' && elementKind == ElementKind.PACKAGE) { logger.log(Level.FINER, "Accepting package ''{0}'' and continuing completion", name); Completion.get().hideDocumentation(); Completion.get().hideCompletion(); JTextComponent tc = (JTextComponent) evt.getSource(); BaseDocument doc = (BaseDocument) tc.getDocument(); doc.runAtomic(new Runnable() { @Override public void run() { try { doc.remove(dotOffset, caretOffset - dotOffset); doc.insertString(dotOffset, name.concat("."), null); } catch (BadLocationException ble) { //ignore } } }); Completion.get().showCompletion(); evt.consume(); } // detect if Ctrl + Enter is pressed overwrite = evt.getKeyCode() == KeyEvent.VK_ENTER && (evt.getModifiers() & KeyEvent.CTRL_MASK) != 0; }
Example 8
Source File: DeadKeyMacOSXInputText.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public void keyTyped(KeyEvent e) { int keyCode = e.getKeyCode(); char keyChar = e.getKeyChar(); if (state == 2) { if (keyCode != 0) { throw new RuntimeException("Key code should be undefined."); } if (keyChar != 0xE1) { throw new RuntimeException("A char does not have ACCUTE accent"); } state++; } else { throw new RuntimeException("Wron number of keyTyped events."); } }
Example 9
Source File: AWTKeyInput.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void onKeyEvent(KeyEvent keyEvent, boolean pressed) { int code = convertKeyCode(keyEvent.getID()); char keyChar = keyEvent.getKeyChar(); final KeyInputEvent event = new KeyInputEvent(code, keyChar, pressed, false); event.setTime(getInputTimeNanos()); EXECUTOR.addToExecute(new Runnable() { @Override public void run() { keyInputEvents.add(event); } }); }
Example 10
Source File: deadKeyMacOSX.java From hottub with GNU General Public License v2.0 | 6 votes |
@Override public void keyTyped(KeyEvent e) { int keyCode = e.getKeyCode(); char keyChar = e.getKeyChar(); if (state == 3) { if (keyCode != 0) { throw new RuntimeException("Key code should be undefined."); } if (keyChar != 0xE1) { throw new RuntimeException("A char does not have ACCUTE accent"); } } else { throw new RuntimeException("Wron number of keyTyped events."); } }
Example 11
Source File: DatabaseManagerSwing.java From evosql with Apache License 2.0 | 5 votes |
public void keyTyped(KeyEvent k) { if (k.getKeyChar() == '\n' && k.isControlDown()) { k.consume(); executeCurrentSQL(); } }
Example 12
Source File: DatabaseManager.java From evosql with Apache License 2.0 | 5 votes |
public void keyTyped(KeyEvent k) { if (k.getKeyChar() == '\n' && k.isControlDown()) { k.consume(); execute(); } }
Example 13
Source File: FSCompletion.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void processKeyEvent(KeyEvent evt) { if (evt.getID() == KeyEvent.KEY_TYPED) { String strToAdd = "/"; if (evt.getKeyChar() == '/') { doSubstitute((JTextComponent) evt.getSource(), strToAdd, strToAdd.length() - 1); evt.consume(); } } }
Example 14
Source File: TelephoneTextField.java From Spark with Apache License 2.0 | 5 votes |
public void keyTyped(KeyEvent keyEvent) { if(keyEvent.getKeyChar() == KeyEvent.VK_ENTER){ if(pad != null){ pad.hide(); } return; } if(pad != null){ pad.numberEntered(keyEvent.getKeyChar()); } }
Example 15
Source File: GPTreeTableBase.java From ganttproject with GNU General Public License v3.0 | 5 votes |
@Override protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { if (isStartEditingEvent(e, false)) { // It is an action which is supposed to start cell editing, but it is not // typing any character. Such actions are F2, Insert and Ctrl+T in the Gantt chart. // We want to select all existing text but do not clear it. putClientProperty("GPTreeTableBase.selectAll", true); putClientProperty("GPTreeTableBase.clearText", false); } else { putClientProperty("GPTreeTableBase.selectAll", false); putClientProperty("GPTreeTableBase.clearText", true); // Otherwise let's check if it is a character and ctrl/meta is not pressed. if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED && !e.isMetaDown() && !e.isControlDown()) { // In this case we want to clear existing text. putClientProperty("GPTreeTableBase.clearText", true); } else { putClientProperty("GPTreeTableBase.clearText", false); } } if (e.getKeyChar() == '>' && ((ks.getModifiers() | KeyEvent.CTRL_DOWN_MASK) > 0)) { return super.processKeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_GREATER, ks.getModifiers()), e, condition, pressed); } if (e.getKeyChar() == '<' && ((ks.getModifiers() | KeyEvent.CTRL_DOWN_MASK) > 0)) { return super.processKeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LESS, ks.getModifiers()), e, condition, pressed); } // See also overridden method editCellAt. return super.processKeyBinding(ks, e, condition, pressed); }
Example 16
Source File: NativeDisplayKeyListener.java From salty-engine with Apache License 2.0 | 5 votes |
@Override public void keyPressed(final KeyEvent e) { if (keyboardHandler != null) { keyboardHandler.keyPressed(e); } currentKey = e.getKeyChar(); if (e.getKeyCode() == KeyEvent.VK_W || e.getKeyCode() == KeyEvent.VK_UP) { inputUp = true; } if (e.getKeyCode() == KeyEvent.VK_S || e.getKeyCode() == KeyEvent.VK_DOWN) { inputDown = true; } if (e.getKeyCode() == KeyEvent.VK_A || e.getKeyCode() == KeyEvent.VK_LEFT) { inputLeft = true; } if (e.getKeyCode() == KeyEvent.VK_D || e.getKeyCode() == KeyEvent.VK_RIGHT) { inputRight = true; } if (SceneManager.getCurrentScene().getUI() != null) { SceneManager.getCurrentScene().getUI().keyPressed(e); } Input.keyboardInput.handleKeyPressed(e); updateInputStates(); Input.lastInput = e; Input.getKeyboardHandlers().forEach(keyboardInputHandler -> keyboardInputHandler.keyPressed(e)); }
Example 17
Source File: InstructionCommentsDataModel.java From binnavi with Apache License 2.0 | 4 votes |
@Override /** * Please read the comment in the base class regarding this method - it is somewhat counter- * intuitive for people used to the Swing keyboard handling model. */ public void keyPressedOrTyped(CodeDisplayCoordinate coordinate, KeyEvent event) { if (!isEditable(coordinate)) { return; } // Are there any existing comments? INaviInstruction instruction = internalData.get(coordinate.getRow()).first(); Pair<IComment, Pair<Integer, Integer>> commentAndIndex = getCommentAndIndexAtCoordinate(coordinate); IComment comment = commentAndIndex.first(); Pair<Integer, Integer> indices = commentAndIndex.second(); switch (event.getKeyCode()) { // VK_UNDEFINED implies that this was a KEY_TYPED event. case KeyEvent.VK_UNDEFINED: switch (event.getKeyChar()) { case java.awt.Event.ENTER: handleRegularKeyInComment(instruction, comment, indices, coordinate, event); coordinate.setLine(coordinate.getLine() + 1); coordinate.setFieldIndex(0); break; case java.awt.Event.BACK_SPACE: handleBackspaceKeyInComment(instruction, comment, indices, coordinate); break; case java.awt.Event.DELETE: handleDeleteKeyInComment(instruction, comment, indices, coordinate); break; default: handleRegularKeyInComment(instruction, comment, indices, coordinate, event); coordinate.setFieldIndex(coordinate.getFieldIndex() + 1); break; } break; case KeyEvent.VK_HOME: coordinate.setFieldIndex(0); break; case KeyEvent.VK_END: coordinate.setFieldIndex(indices.second() - indices.first()); break; default: Logger.warning("Default case in keyTyped hit, investigate why."); break; } }
Example 18
Source File: CodePointInputMethod.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * This is the input method's main routine. The composed text is stored * in buffer. */ public void dispatchEvent(AWTEvent event) { // This input method handles KeyEvent only. if (!(event instanceof KeyEvent)) { return; } KeyEvent e = (KeyEvent) event; int eventID = event.getID(); boolean notInCompositionMode = buffer.length() == 0; if (eventID == KeyEvent.KEY_PRESSED) { // If we are not in composition mode, pass through if (notInCompositionMode) { return; } switch (e.getKeyCode()) { case KeyEvent.VK_LEFT: moveCaretLeft(); break; case KeyEvent.VK_RIGHT: moveCaretRight(); break; } } else if (eventID == KeyEvent.KEY_TYPED) { char c = e.getKeyChar(); // If we are not in composition mode, wait a back slash if (notInCompositionMode) { // If the type character is not a back slash, pass through if (c != '\\') { return; } startComposition(); // Enter to composition mode } else { switch (c) { case ' ': // Exit from composition mode finishComposition(); break; case '\u007f': // Delete deleteCharacter(); break; case '\b': // BackSpace deletePreviousCharacter(); break; case '\u001b': // Escape cancelComposition(); break; case '\n': // Return case '\t': // Tab sendCommittedText(); break; default: composeUnicodeEscape(c); break; } } } else { // KeyEvent.KEY_RELEASED // If we are not in composition mode, pass through if (notInCompositionMode) { return; } } e.consume(); }
Example 19
Source File: ConfigurationsComboModel.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void keyPressed(KeyEvent ke) { if (ke.getKeyChar() == KeyEvent.VK_ENTER || ke.getKeyCode() == KeyEvent.VK_ESCAPE) { confirm(ke); } }
Example 20
Source File: FindReplaceUtility.java From groovy with Apache License 2.0 | 4 votes |
public void keyTyped(KeyEvent ke) { if (ke.getKeyChar() == KeyEvent.VK_ENTER) { FIND_BUTTON.doClick(); } }