.filter(key -> key.isControlDown() && key.getCode().equals(KeyCode.SPACE)) .map(searchPoint -> myCodeArea.getCaretPosition());
@SuppressWarnings("deprecated") public static int convertToKeyCodeId(KeyCode keyCode) { return keyCode.impl_getCode(); }
@SuppressWarnings("deprecation") public static KeyCode findKeyCode(char character) { if (KEY_CODES.containsKey(character)) { return KEY_CODES.get(character); } KeyCode keyCode = KeyCode.getKeyCode(String.valueOf(Character.toUpperCase(character))); if (keyCode != null) { return keyCode; } for (KeyCode code : KeyCode.values()) { if ((char) code.impl_getCode() == character) { return code; } } throw new IllegalArgumentException("No KeyCode found for character: " + character); } }
public class KeysMapper { private static HashMap<Character, Integer> charMap = new HashMap<Character, Integer>(); static { for (KeyCode keyCode : KeyCode.values()) { if (keyCode.impl_getCode() >= 65 && keyCode.impl_getCode() <= 90){ charMap.put(keyCode.getName().toLowerCase().toCharArray()[0], keyCode.impl_getCode()); } else{ charMap.put(keyCode.getName().toLowerCase().toCharArray()[0], keyCode.impl_getCode()); } } } public static Key charToKey(char c){ if(c>=65 && c<=90){ return new Key(charMap.get(c), true); } else { return new Key(charMap.get(c), false); } } public static List<Key> stringToKeys(String text){ List<Key> keys = new ArrayList<Key>(); for (char c : text.toCharArray()) { keys.add(charToKey(c)); } return keys; }
private <T> void keyPressed(KeyEvent event) { KeyCode code = event.getCode(); if (code.isLetterKey() || code.isDigitKey() || code == KeyCode.SPACE) { String letter = code.getChar(); if (event.getSource() instanceof ComboBox) { ComboBox<T> comboBox = (ComboBox<T>) event.getSource(); T item = getEntryWithKey(letter, comboBox.getConverter(), comboBox.getItems(), comboBox); if (item != null) { comboBox.setValue(item); } } else if (event.getSource() instanceof ChoiceBox) { ChoiceBox<T> choiceBox = (ChoiceBox<T>) event.getSource(); T item = getEntryWithKey(letter, choiceBox.getConverter(), choiceBox.getItems(), choiceBox); if (item != null) { choiceBox.setValue(item); } } } }
@Override public void handle(KeyEvent event) { if (event.getCode().equals(KeyCode.Q) && event.isControlDown()) { event.consume(); Platform.exit(); } }
@SuppressWarnings("deprecation") @Override public void pressNoWait( KeyCode key ) { robot.keyPress( key.impl_getCode() ); }
@SuppressWarnings("deprecation") public static KeyCode findKeyCode(char character) { if (KEY_CODES.containsKey(character)) { return KEY_CODES.get(character); } KeyCode keyCode = KeyCode.getKeyCode(String.valueOf(Character.toUpperCase(character))); if (keyCode != null) { return keyCode; } for (KeyCode code : KeyCode.values()) { if ((char) code.impl_getCode() == character) { return code; } } throw new IllegalArgumentException("No KeyCode found for character: " + character); } }
fxView.setOnKeyPressed(e -> { KeyCode keyCode = e.getCode(); if (keyCode.equals(KeyCode.F5) || (keyCode.equals(KeyCode.R) && e.isControlDown())) { reload(); if (keyCode.equals(KeyCode.LEFT) && e.isControlDown()) { goBack(); if (keyCode.equals(KeyCode.RIGHT) && e.isControlDown()) { goForward(); if (keyCode.equals(KeyCode.Q) && e.isControlDown()) { System.exit(0);
@SuppressWarnings("deprecation") @Override public void releaseNoWait( KeyCode key ) { robot.keyRelease( key.impl_getCode() ); }
@Override public void handle(KeyEvent event) { try { if (event.getCode().equals(KeyCode.F10)) { cheatModeActive = !cheatModeActive; logger.debug("Toggle cheatmode. Cheat active: {}", cheatModeActive); } else { if (cheatModeActive && event.isControlDown()) { if (event.getCode().equals(KeyCode.S)) { logger.debug("Cheat created a new ship in " + city.getName()); if (event.getCode().equals(KeyCode.W)) { if (event.getCode().equals(KeyCode.V)) { debugOutputOn = !debugOutputOn; List<String> loggerNames = getLoggerNames();
@SuppressWarnings("deprecation") @Override public void press( KeyCode key ) { robot.keyPress( key.impl_getCode() ); FXTestUtils.awaitEvents(); }
public static String showConfirm(String title, String message, String... options) { final Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.initStyle(StageStyle.UTILITY); alert.setTitle("Choose an option"); alert.setHeaderText(title); alert.setContentText(message); // To make enter key press the actual focused button, not the first one. // Just like pressing // "space". alert.getDialogPane().addEventFilter(KeyEvent.KEY_PRESSED, event -> { if (event.getCode().equals(KeyCode.ENTER)) { event.consume(); } }); if (options == null || options.length == 0) { options = new String[] {OK, CANCEL}; } final List<ButtonType> buttons = new ArrayList<>(); for (final String option : options) { buttons.add(new ButtonType(option)); } alert.getButtonTypes().setAll(buttons); final Optional<ButtonType> result = alert.showAndWait(); if (!result.isPresent()) { return CANCEL; } else { return result.get().getText(); } }
@SuppressWarnings("deprecation") static final int convertEventToModifiedAccelerator(final KeyEvent event) { int modifiers = getStateMask(event) & FxKeyLookup.MODIFIER_MASK; return modifiers + event.getCode().impl_getCode(); // char character = topKey(event); // return modifiers + toUpperCase(character); }
}); EventHandler<KeyEvent> closeKeyHandler = event -> { if (event.getCode().equals(KeyCode.ESCAPE)) { Platform.runLater(() -> { try {
@SuppressWarnings("deprecation") @Override public void release( KeyCode key ) { robot.keyRelease( key.impl_getCode() ); FXTestUtils.awaitEvents(); }
/** * Handles the key events to change the current planning time and * planning time step duration. */ @Override public void handle(KeyEvent event) { if (KeyCode.RIGHT.equals(event.getCode())) { if (event.isControlDown()) { if (0 > this.duration.compareTo(DURATION_MAX)) { this.duration = this.duration.plusMinutes(1); } } else { this.picker.setLocalDateTime(this.picker.getLocalDateTime().plus(this.duration)); this.picker.getValueValidationCallback().call(this.picker.getLocalDateTime()); } event.consume(); } else if (KeyCode.LEFT.equals(event.getCode())) { if (event.isControlDown()) { if (0 < this.duration.compareTo(Duration.ZERO)) { this.duration = this.duration.minusMinutes(1); } } else { this.picker.setLocalDateTime(this.picker.getLocalDateTime().minus(this.duration)); this.picker.getValueValidationCallback().call(this.picker.getLocalDateTime()); } event.consume(); } }
@SuppressWarnings("deprecation") static int convertEventToUnmodifiedAccelerator(KeyEvent event) { int modifiers = getStateMask(event) & FxKeyLookup.MODIFIER_MASK; return modifiers + event.getCode().impl_getCode(); }
@Override public void handle(KeyEvent event) { if (KeyCode.TAB.equals(event.getCode())) { if (lowThumb.isFocused()) { if (event.isShiftDown()) { lowThumb.setFocus(false); new ParentTraversalEngine( rangeSlider.getScene().getRoot(), algorithm) .select(lowThumb, Direction.PREVIOUS) .requestFocus(); } else { lowThumb.setFocus(false); highThumb.setFocus(true); } event.consume(); } else if (highThumb.isFocused()) { if(event.isShiftDown()) { highThumb.setFocus(false); lowThumb.setFocus(true); } else { highThumb.setFocus(false); new ParentTraversalEngine( rangeSlider.getScene().getRoot(), algorithm) .select(highThumb, Direction.NEXT) .requestFocus(); } event.consume(); } } } };
@SuppressWarnings("deprecation") private int getKeyCode(KeyEvent fxEvent) { if (fxEvent.getEventType() == KeyEvent.KEY_TYPED) { return 0; } KeyCode kc = fxEvent.getCode(); switch (kc) { case ALT_GRAPH: return PConstants.ALT; default: break; } return kc.impl_getCode(); }