Java Code Examples for javafx.scene.input.KeyEvent#getEventType()
The following examples show how to use
javafx.scene.input.KeyEvent#getEventType() .
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: ShowPanel.java From oim-fx with MIT License | 6 votes |
public void processKeyEvent(KeyEvent ev) { if (webPage == null) return; ev.consume(); String text = null; String keyIdentifier = null; int windowsVirtualKeyCode = 0; if (ev.getEventType() == KeyEvent.KEY_TYPED) { text = ev.getCharacter(); } else { KeyCodeMap.Entry keyCodeEntry = KeyCodeMap.lookup(ev.getCode()); keyIdentifier = keyCodeEntry.getKeyIdentifier(); windowsVirtualKeyCode = keyCodeEntry.getWindowsVirtualKeyCode(); } WCKeyEvent keyEvent = new WCKeyEvent( idMap.get(ev.getEventType()), text, keyIdentifier, windowsVirtualKeyCode, ev.isShiftDown(), ev.isControlDown(), ev.isAltDown(), ev.isMetaDown(), System.currentTimeMillis()); if (webPage.dispatchKeyEvent(keyEvent)) { ev.consume(); } }
Example 2
Source File: WebViewEventDispatcher.java From oim-fx with MIT License | 6 votes |
private void processKeyEvent(KeyEvent ev) { if (page == null) return; String text = null; String keyIdentifier = null; int windowsVirtualKeyCode = 0; if(ev.getEventType() == KeyEvent.KEY_TYPED) { text = ev.getCharacter(); } else { KeyCodeMap.Entry keyCodeEntry = KeyCodeMap.lookup(ev.getCode()); keyIdentifier = keyCodeEntry.getKeyIdentifier(); windowsVirtualKeyCode = keyCodeEntry.getWindowsVirtualKeyCode(); } WCKeyEvent keyEvent = new WCKeyEvent( idMap.get(ev.getEventType()), text, keyIdentifier, windowsVirtualKeyCode, ev.isShiftDown(), ev.isControlDown(), ev.isAltDown(), ev.isMetaDown(), System.currentTimeMillis()); if (page.dispatchKeyEvent(keyEvent)) { ev.consume(); } }
Example 3
Source File: WritePane.java From oim-fx with MIT License | 6 votes |
private void processKeyEvent(KeyEvent ev) { if (webPage == null) return; String text = null; String keyIdentifier = null; int windowsVirtualKeyCode = 0; if (ev.getEventType() == KeyEvent.KEY_TYPED) { text = ev.getCharacter(); } else { KeyCodeMap.Entry keyCodeEntry = KeyCodeMap.lookup(ev.getCode()); keyIdentifier = keyCodeEntry.getKeyIdentifier(); windowsVirtualKeyCode = keyCodeEntry.getWindowsVirtualKeyCode(); } System.out.println(ev.getText()); WCKeyEvent keyEvent = new WCKeyEvent( idMap.get(ev.getEventType()), text, keyIdentifier, windowsVirtualKeyCode, ev.isShiftDown(), ev.isControlDown(), ev.isAltDown(), ev.isMetaDown(), System.currentTimeMillis()); if (webPage.dispatchKeyEvent(keyEvent)) { ev.consume(); } }
Example 4
Source File: WritePanel.java From oim-fx with MIT License | 5 votes |
public void processKeyEvent(KeyEvent ev) { if (webPage == null) return; ev.consume(); String text = null; String keyIdentifier = null; int windowsVirtualKeyCode = 0; if (ev.getEventType() == KeyEvent.KEY_TYPED) { text = ev.getCharacter(); } else { System.out.println(ev.getCode()); KeyCodeMap.Entry keyCodeEntry = KeyCodeMap.lookup(ev.getCode()); keyIdentifier = keyCodeEntry.getKeyIdentifier(); windowsVirtualKeyCode = keyCodeEntry.getWindowsVirtualKeyCode(); } WCKeyEvent keyEvent = new WCKeyEvent( idMap.get(ev.getEventType()), text, keyIdentifier, windowsVirtualKeyCode, ev.isShiftDown(), ev.isControlDown(), ev.isAltDown(), ev.isMetaDown(), System.currentTimeMillis()); if (webPage.dispatchKeyEvent(keyEvent)) { ev.consume(); } }
Example 5
Source File: Keyboard.java From jace with GNU General Public License v2.0 | 5 votes |
public EventHandler<KeyEvent> getListener() { return (KeyEvent event) -> { if (event.getEventType() == KeyEvent.KEY_PRESSED) { keyPressed(event); } else if (event.getEventType() == KeyEvent.KEY_RELEASED) { keyReleased(event); } }; }
Example 6
Source File: CameraController.java From FXyzLib with GNU General Public License v3.0 | 5 votes |
private void handleKeyEvent(KeyEvent t) { if (t.getEventType() == KeyEvent.KEY_PRESSED) { handleKeyEvent(t, true); } else if (t.getEventType() == KeyEvent.KEY_RELEASED) { handleKeyEvent(t, true); } speed = getSpeedModifier(t); }
Example 7
Source File: ConsoleKeyEvent.java From dm3270 with Apache License 2.0 | 5 votes |
@Override public void handle (KeyEvent e) // onKeyTyped { if (e.getEventType () != KeyEvent.KEY_TYPED) return; String c = e.getCharacter (); if (c.isEmpty ()) return; char ch = c.charAt (0); if (screen.isKeyboardLocked () || e.isMetaDown () || e.isControlDown () || e.isAltDown ()) { // seems to be a bug in java if (e.isMetaDown ()) { if (ch == '-') // osx fix { screen.getFontManager ().smaller (); e.consume (); } else if (ch == '=') // osx fix { screen.getFontManager ().bigger (); e.consume (); } } return; } if (ch >= 32 && ch < 0x7F) { cursor.typeChar ((byte) Dm3270Utility.asc2ebc[ch]); e.consume (); } }
Example 8
Source File: ConsoleKeyEvent.java From xframium-java with GNU General Public License v3.0 | 5 votes |
@Override public void handle (KeyEvent e) // onKeyTyped { if (e.getEventType () != KeyEvent.KEY_TYPED) return; String c = e.getCharacter (); if (c.isEmpty ()) return; char ch = c.charAt (0); if (screen.isKeyboardLocked () || e.isMetaDown () || e.isControlDown () || e.isAltDown ()) { // seems to be a bug in java if (e.isMetaDown ()) { if (ch == '-') // osx fix { screen.getFontManager ().smaller (); e.consume (); } else if (ch == '=') // osx fix { screen.getFontManager ().bigger (); e.consume (); } } return; } if (ch >= 32 && ch < 0x7F) { cursor.typeChar ((byte) Dm3270Utility.asc2ebc[ch]); e.consume (); } }
Example 9
Source File: EventQueueDeviceTest.java From marathonv5 with Apache License 2.0 | 5 votes |
private static void addToList(KeyEvent e) { final StringBuilder sb = new StringBuilder(); if (e.getEventType() == KeyEvent.KEY_PRESSED) { sb.append(checkModifier(e) + " pressed " + e.getCode()); } if (e.getEventType() == KeyEvent.KEY_RELEASED) { sb.append(checkModifier(e) + " released " + e.getCode()); } kss.add(sb.toString().trim()); }
Example 10
Source File: ChatWritePane.java From oim-fx with MIT License | 5 votes |
public void processKeyEvent(KeyEvent ev) { if (webPage == null) return; ev.consume(); String text = null; String keyIdentifier = null; int windowsVirtualKeyCode = 0; if (ev.getEventType() == KeyEvent.KEY_TYPED) { text = ev.getCharacter(); } else { System.out.println(ev.getCode()); KeyCodeMap.Entry keyCodeEntry = KeyCodeMap.lookup(ev.getCode()); keyIdentifier = keyCodeEntry.getKeyIdentifier(); windowsVirtualKeyCode = keyCodeEntry.getWindowsVirtualKeyCode(); } WCKeyEvent keyEvent = new WCKeyEvent( idMap.get(ev.getEventType()), text, keyIdentifier, windowsVirtualKeyCode, ev.isShiftDown(), ev.isControlDown(), ev.isAltDown(), ev.isMetaDown(), System.currentTimeMillis()); if (webPage.dispatchKeyEvent(keyEvent)) { ev.consume(); } }
Example 11
Source File: ChatShowPane.java From oim-fx with MIT License | 5 votes |
public void processKeyEvent(KeyEvent ev) { if (webPage == null){ return; } ev.consume(); String text = null; String keyIdentifier = null; int windowsVirtualKeyCode = 0; if (ev.getEventType() == KeyEvent.KEY_TYPED) { text = ev.getCharacter(); } else { KeyCodeMap.Entry keyCodeEntry = KeyCodeMap.lookup(ev.getCode()); keyIdentifier = keyCodeEntry.getKeyIdentifier(); windowsVirtualKeyCode = keyCodeEntry.getWindowsVirtualKeyCode(); } WCKeyEvent keyEvent = new WCKeyEvent( idMap.get(ev.getEventType()), text, keyIdentifier, windowsVirtualKeyCode, ev.isShiftDown(), ev.isControlDown(), ev.isAltDown(), ev.isMetaDown(), System.currentTimeMillis()); if (webPage.dispatchKeyEvent(keyEvent)) { ev.consume(); } }
Example 12
Source File: TextAreaReadline.java From marathonv5 with Apache License 2.0 | 4 votes |
@Override public void handle(KeyEvent event) { if (event.getEventType() != KeyEvent.KEY_PRESSED) { return; } KeyCode code = event.getCode(); switch (code) { case ENTER: positionToLastLine(); boolean collect = false; if (area.getText().toString().endsWith(";")) { collect = true; area.setText(area.getText().substring(0, area.getText().length() - 1)); } if (collect || event.isShiftDown()) { collectAction(); } else { if (functionText.length() > 0) { collectAction(); } enterAction(event); area.setEditable(false); } break; case UP: positionToLastLine(); upAction(event); break; case DOWN: positionToLastLine(); downAction(event); break; case LEFT: case D: if (event.isControlDown()) { event.consume(); inputJoin.send(Channel.LINE, EMPTY_LINE); } break; default: break; } }
Example 13
Source File: WSRecorder.java From marathonv5 with Apache License 2.0 | 4 votes |
@Override public void recordRawKeyEvent(RFXComponent r, KeyEvent e) { JSONObject event = new JSONObject(); event.put("type", "key_raw"); KeyCode keyCode = e.getCode(); if (keyCode.isModifierKey()) { return; } if ((keyCode.isFunctionKey() || keyCode.isArrowKey() || keyCode.isKeypadKey() || keyCode.isMediaKey() || keyCode.isNavigationKey() || e.isControlDown() || e.isMetaDown() || e.isAltDown() || needManualRecording(keyCode)) && e.getEventType() == KeyEvent.KEY_PRESSED) { String mtext = buildModifiersText(e); event.put("modifiersEx", mtext); KeysMap keysMap = KeysMap.findMap(e.getCode()); if (keysMap == KeysMap.NULL) { return; } String keyText; if (keysMap == null) { keyText = e.getText(); } else { keyText = keysMap.toString(); } event.put("keyCode", keyText); } else if (e.getEventType() == KeyEvent.KEY_TYPED && !e.isControlDown() && !needManualRecording(keyCode)) { char[] cs = e.getCharacter().toCharArray(); if (cs.length == 0) { return; } for (char c : cs) { if (Character.isISOControl(c) && hasMapping(c)) { event.put("keyChar", getMapping(c)); } else { event.put("keyChar", "" + c); } } } else { return; } recordEvent(r, event); }
Example 14
Source File: KeyEventHandler.java From CrazyAlpha with GNU General Public License v2.0 | 4 votes |
@Override public void handle(KeyEvent keyEvent) { boolean mapShake = false; if (keyEvent.getEventType() == KeyEvent.KEY_PRESSED) { // 地图震动 if (mapShake) Game.getInstance().getMapManager().getCurrentMap().start(); ((CenterArc) Game.getInstance().getModelManager().get("CenterArc")).changeStrokeColor(); String keyAlpha = keyEvent.getText().toUpperCase(); Alpha alpha = (Alpha) Game.getInstance().getModelManager().get(keyAlpha); if (alpha == null) { Game.getInstance().getMissMusic().play(); ((HPIndicator) Game.getInstance().getModelManager().get("HPIndicator")).miss(); logger.info("missed {} !", keyAlpha); return; } if (alpha.getStatus() == ObjectStatus.ANIMATION) { Game.getInstance().debug("hint {}!", keyAlpha); Game.getInstance().getHintMusic().play(); int gainScore = ((ScoreIndicator) Game.getInstance().getModelManager().get("ScoreIndicator")).hint(alpha); ScoreGadget scoreGadget = (ScoreGadget) Game.getInstance().getModelManager().getInvisibleModel(ScoreGadget.class); if (scoreGadget == null) scoreGadget = new ScoreGadget(); scoreGadget.setText("+" + String.valueOf(gainScore)); scoreGadget.setX(alpha.getX()); scoreGadget.setY(alpha.getY()); scoreGadget.setFillColor(alpha.getFillColor()); Game.getInstance().getModelManager().register(scoreGadget, String.valueOf(RandomEx.nextInt())); scoreGadget.start(); alpha.stop(); } else { Game.getInstance().getMissMusic().play(); ((HPIndicator) Game.getInstance().getModelManager().get("HPIndicator")).miss(); logger.info("missed {} !", keyAlpha); } } if (keyEvent.getEventType() == KeyEvent.KEY_RELEASED) { if (mapShake) Game.getInstance().getMapManager().getCurrentMap().stop(); Game.getInstance().getHintMusic().stop(); Game.getInstance().getMissMusic().stop(); ((CenterArc) Game.getInstance().getModelManager().get("CenterArc")).changeFillColor(); } if (keyEvent.getCode() == KeyCode.ESCAPE) { if (Game.getInstance().getStatus() == GameStatus.PAUSE) Game.getInstance().resume(); else if (Game.getInstance().getStatus() == GameStatus.RUNNING) Game.getInstance().pause(); } }
Example 15
Source File: KeyMap.java From FxDock with Apache License 2.0 | 4 votes |
protected static KKey key(KeyEvent ev) { int flags = 0; KeyCode cd; String ch; if(ev.getEventType() == KeyEvent.KEY_PRESSED) { flags |= KEY_PRESSED; cd = ev.getCode(); ch = null; } else if(ev.getEventType() == KeyEvent.KEY_RELEASED) { flags |= KEY_RELEASED; cd = ev.getCode(); ch = null; } else if(ev.getEventType() == KeyEvent.KEY_TYPED) { flags |= KEY_TYPED; cd = null; ch = ev.getCharacter(); } else { throw new Error("?" + ev.getEventType()); } if(ev.isAltDown()) { flags |= ALT; } if(ev.isControlDown()) { flags |= CTRL; } if(ev.isMetaDown()) { flags |= META; } if(ev.isShiftDown()) { flags |= SHIFT; } if(ev.isShortcutDown()) { flags |= ACTUAL_SHORTCUT; } // D.f("key event 0x%8x %s", flags, ev.getCode()); return new KKey(flags, cd, ch); }
Example 16
Source File: FPSController.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
@Override public void handleKeyEvent(KeyEvent event, boolean handle) { if (event.getEventType() == KeyEvent.KEY_PRESSED) { switch (event.getCode()) { case W: fwd = true; break; case S: back = true; break; case A: strafeL = true; break; case D: strafeR = true; break; case SHIFT: shift = true; if(up || down){ break; } speed = maxSpeed; break; case SPACE: if (!shift) { up = true; } else if (shift) { down = true; } break; } } else if (event.getEventType() == KeyEvent.KEY_RELEASED) { switch (event.getCode()) { case W: fwd = false; break; case S: back = false; break; case A: strafeL = false; break; case D: strafeR = false; break; case SHIFT: speed = minSpeed; shift = false; break; case SPACE: up = false; down = false; break; } } }
Example 17
Source File: DragSupport.java From scenic-view with GNU General Public License v3.0 | 4 votes |
public DragSupport(Node target, final KeyCode modifier, final MouseButton mouseButton, final Orientation orientation, final Property<Number> property, final double factor) { this.target = target; mouseEventHandler = new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent t) { if (t.getEventType() != MouseEvent.MOUSE_ENTERED_TARGET && t.getEventType() != MouseEvent.MOUSE_EXITED_TARGET) { lastMouseEvent = t; } if (t.getEventType() == MouseEvent.MOUSE_PRESSED) { if (t.getButton() == mouseButton && isModifierCorrect(t, modifier)) { anchor = property.getValue(); dragAnchor = getCoord(t, orientation); t.consume(); } } else if (t.getEventType() == MouseEvent.MOUSE_DRAGGED) { if (t.getButton() == mouseButton && isModifierCorrect(t, modifier)) { property.setValue(anchor.doubleValue() + (getCoord(t, orientation) - dragAnchor) * factor); t.consume(); } } } }; keyboardEventHandler = (KeyEvent t) -> { if (t.getEventType() == KeyEvent.KEY_PRESSED) { if (t.getCode() == modifier) { anchor = property.getValue(); if (lastMouseEvent != null) { dragAnchor = getCoord(lastMouseEvent, orientation); } t.consume(); } } else if (t.getEventType() == KeyEvent.KEY_RELEASED) { if (t.getCode() != modifier && isModifierCorrect(t, modifier)) { anchor = property.getValue(); if (lastMouseEvent != null) { dragAnchor = getCoord(lastMouseEvent, orientation); } t.consume(); } } }; target.addEventHandler(MouseEvent.ANY, mouseEventHandler); target.addEventHandler(KeyEvent.ANY, keyboardEventHandler); }