本文整理了Java中javafx.scene.input.KeyEvent
类的一些代码示例,展示了KeyEvent
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyEvent
类的具体详情如下:
包路径:javafx.scene.input.KeyEvent
类名称:KeyEvent
暂无
代码示例来源:origin: stackoverflow.com
textField.setOnKeyPressed(new EventHandler<KeyEvent>()
{
@Override
public void handle(KeyEvent ke)
{
if (ke.getCode().equals(KeyCode.ENTER))
{
doSomething();
}
}
});
代码示例来源:origin: jfoenixadmin/JFoenix
private void initNavigation() {
setOnKeyPressed(ke -> {
switch (ke.getCode()) {
case SPACE:
case ENTER:
// select the focused color
if (focusedSquare != null) {
focusedSquare.selectColor(ke);
}
ke.consume();
break;
default: // no-op
}
});
}
代码示例来源:origin: jfoenixadmin/JFoenix
editor.setWrapText(true);
editor.addEventFilter(KeyEvent.KEY_RELEASED, event -> {
if (event.getCode() != KeyCode.ENTER) {
getSkinnable().pseudoClassStateChanged(PSEUDO_CLASS_ERROR, false);
switch (event.getCode()) {
case ENTER:
if (!editor.getText().trim().isEmpty()) {
event.consume();
break;
if (event.isShiftDown()) {
getBehavior().traverse(getSkinnable(), Direction.PREVIOUS);
} else {
event.consume();
break;
if (event.isControlDown()) {
if (!autoCompletePopup.getFilteredSuggestions().isEmpty()) {
autoCompletePopup.show(editor);
control.addEventFilter(KeyEvent.ANY, ke -> {
if (editor != null) {
if (ke.getTarget().equals(editor)) {
return;
if (ke.getTarget().equals(control)) {
代码示例来源:origin: jfoenixadmin/JFoenix
private void createEditorNode() {
EventHandler<KeyEvent> keyEventsHandler = t -> {
if (t.getCode() == KeyCode.ENTER) {
commitHelper(false);
} else if (t.getCode() == KeyCode.ESCAPE) {
cancelEdit();
} else if (t.getCode() == KeyCode.TAB) {
commitHelper(false);
editNext(!t.isShiftDown());
}
};
ChangeListener<Boolean> focusChangeListener = (observable, oldValue, newValue) -> {
//This focus listener fires at the end of cell editing when focus is lost
//and when enter is pressed (because that causes the text field to lose focus).
//The problem is that if enter is pressed then cancelEdit is called before this
//listener runs and therefore the text field has been cleaned up. If the
//text field is null we don't commit the edit. This has the useful side effect
//of stopping the double commit.
if (editorNode != null && !newValue) {
commitHelper(true);
}
};
editorNode = builder.createNode(getValue(), keyEventsHandler, focusChangeListener);
}
代码示例来源:origin: pmd/pmd
.filter(e -> !e.isConsumed())
.filter(e ->
e.getEventType().equals(KeyEvent.KEY_RELEASED) && e.getCode() == KeyCode.ENTER
|| e.getEventType().equals(KeyEvent.KEY_PRESSED) && e.getCode() == KeyCode.TAB
autoCompletePopup.getItems().get(focusIdx).getOnAction().handle(new ActionEvent());
e.consume();
});
.filter(key -> key.isControlDown() && key.getCode().equals(KeyCode.SPACE))
.map(searchPoint -> myCodeArea.getCaretPosition());
代码示例来源:origin: eu.mihosoft.vrl.jcsg/jcsg
private boolean isModifierCorrect(KeyEvent t, KeyCode keyCode) {
return (keyCode != KeyCode.ALT ^ t.isAltDown())
&& (keyCode != KeyCode.CONTROL ^ t.isControlDown())
&& (keyCode != KeyCode.SHIFT ^ t.isShiftDown())
&& (keyCode != KeyCode.META ^ t.isMetaDown());
}
代码示例来源:origin: org.tentackle/tentackle-fx
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void setType(Class<?> type) {
super.setType(type);
// choice box does not need a value translator because the items are already of model type
// and choice-box is not editable
// deselect by DELETE- or BACKSPACE-key (with or without shift)
component.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
if (!event.isAltDown() && !event.isControlDown() && !event.isMetaDown() && !event.isShortcutDown() &&
(event.getCode() == KeyCode.DELETE || event.getCode() == KeyCode.BACK_SPACE) &&
!component.isDisabled() && isDeselectAllowed()) {
event.consume();
component.getSelectionModel().clearSelection();
}
});
if (type.isEnum()) {
ObservableList items = component.getItems();
items.clear();
items.addAll(Arrays.asList(type.getEnumConstants()));
}
}
代码示例来源:origin: at.bestsolution.efxclipse.rt/org.eclipse.fx.ui.controls
/**
* The event
*
* @param source
* the source
* @param target
* the target
* @param event
* the key
*/
public VerifyEvent(Object source, EventTarget target, KeyEvent event) {
super(source, target, VERIFY);
boolean isKeyTyped = event.getEventType() == KeyEvent.KEY_TYPED;
this.character = isKeyTyped ? event.getCharacter() : KeyEvent.CHAR_UNDEFINED;
this.text = isKeyTyped ? "" : event.getText(); //$NON-NLS-1$
this.code = isKeyTyped ? KeyCode.UNDEFINED : event.getCode();
this.shiftDown = event.isShiftDown();
this.controlDown = event.isControlDown();
this.altDown = event.isAltDown();
this.metaDown = event.isMetaDown();
}
代码示例来源:origin: ch.sahits.game/OpenPatricianJavaFX
@Override
public void handle(KeyEvent event) {
if (event.getCode().equals(KeyCode.Q) && event.isControlDown()) {
event.consume();
Platform.exit();
}
}
代码示例来源:origin: com.nexitia.emaginplatform/emagin-jfxcore-engine
/**
* Keys CTRL + R: reload steelSheets
*/
protected void initRefreshCTRPlusRListener() {
scene.get().addEventHandler(KeyEvent.KEY_RELEASED, event -> {
switch (event.getCode()) {
case PLUS:
// CTRL + Bigger view
if (event.isControlDown()) {
}
break;
case MINUS:
// CTRL - stretched view
if (event.isControlDown()) {
}
break;
case R:
// CTRL + R ==> refresh CSS
if (event.isControlDown()) {
styleSheetManager.reLoadSteelSheets();
}
break;
default:
break;
}
});
}
代码示例来源:origin: org.controlsfx/controlsfx
@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();
}
}
}
};
代码示例来源:origin: at.bestsolution.eclipse/org.eclipse.fx.ui.controls
if (event.getCode() == KeyCode.ALT || event.isAltDown()) {
event.consume();
event.consume();
return;
switch (event.getCode()) {
case SHIFT:
case ALT:
break;
case LEFT: {
if (event.isAltDown()) {
invokeAction(ActionType.WORD_PREVIOUS);
} else {
if (offset == 0) {
event.consume();
break;
@SuppressWarnings("unused")
int newLine = getControl().getContent().getLineAtOffset(newOffset);
getControl().impl_setCaretOffset(newOffset, event.isShiftDown());
event.consume();
if (event.isAltDown()) {
invokeAction(ActionType.WORD_NEXT);
} else if (event.isMetaDown()) {
int currentLine = getControl().getContent().getLineAtOffset(offset);
int lineOffset = getControl().getContent().getOffsetAtLine(currentLine);
代码示例来源:origin: org.processing/core
@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();
}
代码示例来源:origin: at.bestsolution.efxclipse.rt/org.eclipse.fx.ui.workbench.fx
@SuppressWarnings("deprecation")
static final int convertEventToUnshiftedModifiedAccelerator(final KeyEvent event) {
// Disregard alphabetic key strokes.
if (Character.isLetter(event.getCharacter().charAt(0))) {
return convertEventToUnmodifiedAccelerator(event);
}
int modifiers = getStateMask(event) & (FxKeyLookup.MODIFIER_MASK ^ FxKeyLookup.SHIFT);
return modifiers + event.getCode().impl_getCode();
// char character = topKey(event);
// return modifiers + toUpperCase(character);
}
代码示例来源:origin: at.bestsolution.eclipse/org.eclipse.fx.text.ui
private void handleKeyTyped(KeyEvent event) {
if( event.getCharacter().length() == 0 ) {
return;
String character = event.getCharacter();
if( character.length() == 0 ) {
return;
if (event.isControlDown() || event.isAltDown() || (Util.isMacOS() && event.isMetaDown())) {
if (!((event.isControlDown() || Util.isMacOS()) && event.isAltDown())) {
return;
this.offset += event.getCharacter().length();
代码示例来源:origin: com.github.vatbub/common.view.tagarea
public TagArea() {
this.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
getStyleClass().setAll("tag-area");
textField.setMinSize(80, 30);
textField.setPrefWidth(80);
textField.setOnAction(event -> {
this.addTag(textField.getText());
textField.clear();
});
textField.setOnKeyReleased(event -> {
System.out.println("[Pressed] Pressed Key: " + event.getCode() + ", Character is: " + event.getCharacter());
if (event.getCode() == KeyCode.BACK_SPACE && textField.getText().length() == 0) {
List<Tag> tags = this.getTags();
if (tags.size() != 0) {
Tag lastTag = tags.get(tags.size() - 1);
removeTag(lastTag);
textField.setText(lastTag.getValue());
textField.positionCaret(lastTag.getValue().length());
event.consume();
}
} else if (event.getCode() == KeyCode.COMMA) {
System.out.println("TextField value is: " + textField.getText());
addTag(textField.getText().replaceAll(",", ""));
textField.clear();
event.consume();
}
});
this.getChildren().add(textField);
}
代码示例来源:origin: eu.mihosoft.vrl.jcsg/jcsg
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();
代码示例来源:origin: stackoverflow.com
public class ControllerClass {
private final PauseTransition pauseBeforeSearch = new PauseTransition(Duration.millis(200));
@FXML protected void keyReleased(KeyEvent evt)throws Exception {
if (evt.getCode() != KeyCode.BACK_SPACE) {
pauseBeforeSearch.setOnFinished(e -> {
searchFrmDb(evt.getText(), new String[5]);
});
pauseBeforeSearch.playFromStart();
}
}
}
代码示例来源:origin: com.github.wshackle/poseList3DPlot
private void handleKeyEvent(javafx.scene.input.KeyEvent event) {
if (event.isAltDown()) {
double r = event.isShiftDown() ? 1 : -1;
switch (event.getCode()) {
case X:
composeRotation(r, Vector3D.PLUS_I, rxy);
break;
case Y:
composeRotation(r, Vector3D.PLUS_J, rxy);
break;
case Z:
rz.setAngle(rz.getAngle() + r);
break;
}
} else {
double tinc = event.isShiftDown() ? 10 : -10;
switch (event.getCode()) {
case X:
t.setX(t.getX() + tinc);
break;
case Y:
t.setY(t.getY() + tinc);
break;
case Z:
t.setZ(t.getZ() + tinc);
break;
}
}
}
代码示例来源:origin: org.processing/core
@SuppressWarnings("deprecation")
private char getKeyChar(KeyEvent fxEvent) {
KeyCode kc = fxEvent.getCode();
if (fxEvent.getEventType() == KeyEvent.KEY_TYPED) {
ch = fxEvent.getCharacter();
} else {
ch = kc.impl_getChar();
内容来源于网络,如有侵权,请联系作者删除!