当前位置: 首页>>代码示例>>Java>>正文


Java KeyEvent类代码示例

本文整理汇总了Java中javafx.scene.input.KeyEvent的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent类的具体用法?Java KeyEvent怎么用?Java KeyEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


KeyEvent类属于javafx.scene.input包,在下文中一共展示了KeyEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: openHelp

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
@FXML
public void openHelp(ActionEvent event) throws IOException {
    Parent root = FXMLLoader.load(getClass().getResource("/fxml/helpPopup.fxml"));
    final Scene scene = new Scene(root);
    final Stage stage = new Stage();
    stage.setTitle("Help");
    stage.setScene(scene);
    stage.show();
    stage.setResizable(false);
    stage.centerOnScreen();

    root.setOnKeyPressed(new EventHandler<KeyEvent>() {
        public void handle(KeyEvent ke) {
            if (ke.getCode() == KeyCode.ESCAPE) {
                System.out.println("Key Pressed: " + ke.getCode());
                stage.close();
            }
        }
    });
}
 
开发者ID:dewarian,项目名称:FYS_T3,代码行数:21,代码来源:searchLugController.java

示例2: start

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
public void start(Stage primaryStage, ScrollPane rootLayout) throws Exception {
	primaryStage.setTitle("Change Hotkeys");
	Scene myScene = new Scene(rootLayout);
	ourStage = primaryStage;
	myScene.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
		public void handle(KeyEvent event) {
			if (changeHotkey) {
				if (addHotkey(event, changeHotkeyFunction)) {
					changeHotkey = false;
				}
			}
		}
	});
	Label divider = new Label();
	HBox labelHbox = new HBox(divider);
	divider.setText("----These hotkeys are not changeable----");
	labelHbox.setAlignment(Pos.CENTER);
	for (String key : HOTKEYS) {
		hotkeyVBox.getChildren().add(hotkeys.get(key).getHotkeyHBox());
	}
	hotkeyVBox.getChildren().add(labelHbox);
	for (ImmutableHotkey hotkey : IMMUTABLE_HOTKEYS) {
		hotkeyVBox.getChildren().add(hotkey.getHotkeyHBox());
	}
	primaryStage.setScene(myScene);
}
 
开发者ID:ForJ-Latech,项目名称:fwm,代码行数:27,代码来源:HotkeyController.java

示例3: onKeyPressed

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
private void onKeyPressed(KeyEvent event) {
    if (event.getCode() == KeyCode.ESCAPE) {
        handleSelection(Selection.CANCEL);
    } else if (event.getCode() == KeyCode.ENTER) {
        Node focusOwner = root.getScene().getFocusOwner();
        if (focusOwner instanceof Button) {
            ((Button) (focusOwner)).fire();
        }
    }
}
 
开发者ID:rmfisher,项目名称:fx-animation-editor,代码行数:11,代码来源:SaveDialogComponent.java

示例4: start

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
@Override
public void start(Stage rootStage) throws Exception {
    rootStage.setMaximized(true);
    main = this;

    FXMLLoader loader = new FXMLLoader(getClass().getResource("/resources/layouts/main.fxml"));

    Parent root = loader.load();

    Scene rootScene = new Scene(root);

    rootStage.setTitle("Parallator");

    rootController = loader.getController();

    rootStage.setScene(rootScene);

    initMenu(rootStage);

    rootStage.show();
    rootStage.setOnCloseRequest(event -> {
        if (rootController.getFile() == null || !rootController.isEdited()) return;
        Alert alert = new Alert(Alert.AlertType.WARNING);
        alert.setHeaderText("Сохранить перед выходом?");
        alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO, ButtonType.CANCEL);
        Optional<ButtonType> result = alert.showAndWait();
        if (result.isPresent() && result.get() == ButtonType.YES) {
            rootController.save();
        }
        if (result.isPresent() && result.get() == ButtonType.CANCEL) {
            event.consume();
        }
    });

    rootScene.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
        switch (event.getCode()) {
            case DOWN:
                rootController.down();
                break;
            case UP:
                rootController.up();
                break;
        }
    });

    if (MainConfig.getMainConfig().path() != null) rootController.open(new File(MainConfig.getMainConfig().path()));
}
 
开发者ID:KursX,项目名称:Parallator,代码行数:48,代码来源:Main.java

示例5: updateRotation

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
/**
 * Updating rotation.
 */
@FXThread
private void updateRotation(@Nullable final KeyEvent event) {
    if (isIgnoreListener() || (event != null && event.getCode() != KeyCode.ENTER)) return;

    final Quaternion oldValue = notNull(getPropertyValue());

    final FloatTextField xField = getXField();
    final float x = degreeToRadians(xField.getValue());

    final FloatTextField yFiled = getYFiled();
    final float y = degreeToRadians(yFiled.getValue());

    final FloatTextField zField = getZField();
    final float z = degreeToRadians(zField.getValue());

    final Quaternion newValue = new Quaternion();
    newValue.fromAngles(ArrayFactory.toFloatArray(x, y, z));

    changed(newValue, oldValue.clone());
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:24,代码来源:QuaternionPropertyControl.java

示例6: openCreditsAction

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
@FXML
public void openCreditsAction(ActionEvent event) throws IOException {
    Node node = (Node) event.getSource();
    final Stage stage = (Stage) node.getScene().getWindow();
    Parent root = FXMLLoader.load(getClass().getResource("/fxml/Credits.fxml"));
    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();

    final Parent home = FXMLLoader.load(getClass().getResource("/fxml/Homepage.fxml"));
    final Scene hScene = new Scene(home);
    root.setOnKeyPressed(new EventHandler<KeyEvent>() {
        public void handle(KeyEvent ke) {
            if (ke.getCode() == KeyCode.ESCAPE) {
                System.out.println("Key Pressed: " + ke.getCode());
                stage.setScene(hScene);
            }
        }
    });
}
 
开发者ID:dewarian,项目名称:FYS_T3,代码行数:21,代码来源:homepageController.java

示例7: enterAction

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
protected void enterAction(KeyEvent event) {
    event.consume();
    if (functionText.length() > 0) {
        String function = functionText.toString();
        append(">> ", promptStyle);
        append(function, inputStyle);
        inputJoin.send(Channel.LINE, function);
    } else {
        String text = area.getText();
        append(">> ", promptStyle);
        append(text, inputStyle);
        append("\n", inputStyle);
        String line = getLine();
        inputJoin.send(Channel.LINE, line);
    }
    functionText = new StringBuffer();
    area.clear();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:19,代码来源:TextAreaReadline.java

示例8: ketEventGetModifiersExText

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
public static String ketEventGetModifiersExText(KeyEvent event) {
    StringBuffer sb = new StringBuffer();

    if (event.isControlDown()) {
        sb.append("Ctrl+");
    }
    if (event.isMetaDown()) {
        sb.append("Meta+");
    }
    if (event.isAltDown()) {
        sb.append("Alt+");
    }
    if (event.isShiftDown()) {
        sb.append("Shift+");
    }
    String text = sb.toString();
    if (text.equals("")) {
        return text;
    }
    return text.substring(0, text.length() - 1);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:22,代码来源:OSFXUtils.java

示例9: sendKey

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
private void sendKey(Node node, char c) {
    node = getActiveNode(node);
    JavaAgentKeys keys = JavaAgentKeys.getKeyFromUnicode(c);
    if (keys == null) {
        dispatchKeyEvent(node, null, KeyEvent.KEY_PRESSED, c);
        if (deviceState.getModifierEx() == 0) {
            dispatchKeyEvent(node, null, KeyEvent.KEY_TYPED, c);
        }
        dispatchKeyEvent(node, null, KeyEvent.KEY_RELEASED, c);
        return;
    }
    if (keys == JavaAgentKeys.NULL) {
        resetModifierState(node);
    } else if (deviceState.isModifier(keys)) {
        pressKey(node, keys);
    } else {
        pressKey(node, keys);
        if (keys == JavaAgentKeys.SPACE) {
            dispatchKeyEvent(node, null, KeyEvent.KEY_TYPED, ' ');
        }
        releaseKey(node, keys);
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:24,代码来源:FXEventQueueDevice.java

示例10: checkModifier

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
private static String checkModifier(KeyEvent e) {
    String s = "";
    if (e.isShiftDown()) {
        s = "Shift";
    }
    if (e.isControlDown()) {
        s = "Ctrl";
    }
    if (e.isAltDown()) {
        s = "Alt";
    }
    if (e.isMetaDown()) {
        s = "Meta";
    }
    return s;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:17,代码来源:EventQueueDeviceTest.java

示例11: setArgCompletion

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
/**
 * Adds an auto-completion to a certain argument - Must be added in decreasing order
 * @param index Arg index
 * @param completion Completion type
 */
@SuppressWarnings("deprecation")
protected void setArgCompletion(int index, TabCompletion completion) {
    completions.put(index, completion);
    Nodes.TEXTFIELD.addEventHandler(KeyEvent.KEY_RELEASED, e -> {
        if(e.getCode() == KeyCode.TAB) {
            String t = Nodes.TEXTFIELD.getText() + "\0";
            String[] args = Formatter.getInstance().format(t).split(" ");
            if(args.length == 1 && args[0].replace("\0", "").isEmpty() && completion instanceof InitialCommandTabCompletion) {
                completion.onTab(new String[] {""});
            }
            else if(args.length > 0 && (args[0].equals(name) || args.length == 1)) {
                if(args.length == index + 2) {
                    List<String> list = Arrays.asList(args);
                    list.set(list.size()-1, list.get(list.size()-1).replace("\0", ""));
                    completion.onTab(list.toArray(new String[list.size()]));
                }
            }
        }
    });
}
 
开发者ID:iAmGio,项目名称:jrfl,代码行数:26,代码来源:Command.java

示例12: buildModifiersText

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
private String buildModifiersText(KeyEvent e) {
    StringBuilder sb = new StringBuilder();
    if (e.isAltDown()) {
        sb.append("Alt+");
    }
    if (e.isControlDown()) {
        sb.append("Ctrl+");
    }
    if (e.isMetaDown()) {
        sb.append("Meta+");
    }
    if (e.isShiftDown()) {
        sb.append("Shift+");
    }
    if (sb.length() > 0) {
        sb.setLength(sb.length() - 1);
    }
    String mtext = sb.toString();
    return mtext;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:21,代码来源:WSRecorder.java

示例13: openStatisticsAction

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
@FXML
public void openStatisticsAction(ActionEvent event) throws IOException {
    Node node = (Node) event.getSource();
    final Stage stage = (Stage) node.getScene().getWindow();
    Parent root = FXMLLoader.load(getClass().getResource("/fxml/Statistics.fxml"));
    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();

    final Parent home = FXMLLoader.load(getClass().getResource("/fxml/Homepage.fxml"));
    final Scene hScene = new Scene(home);
    root.setOnKeyPressed(new EventHandler<KeyEvent>() {
        public void handle(KeyEvent ke) {
            if (ke.getCode() == KeyCode.ESCAPE) {
                System.out.println("Key Pressed: " + ke.getCode());
                stage.setScene(hScene);
            }
        }
    });
}
 
开发者ID:dewarian,项目名称:FYS_T3,代码行数:21,代码来源:homepageController.java

示例14: isContextMenuKeyEvent

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
private boolean isContextMenuKeyEvent(KeyEvent event) {
    if (!event.getEventType().equals(KeyEvent.KEY_PRESSED)) {
        return false;
    }
    if (event.getCode() == KeyCode.CONTROL || event.getCode() == KeyCode.SHIFT || event.getCode() == KeyCode.ALT
            || event.getCode() == KeyCode.META) {
        return false;
    }
    String keyText = isModifiers(event) ? ketEventGetModifiersExText(event) + "+" : "";
    keyText += keyEventGetKeyText(event.getCode());
    StringBuffer contextMenuText = new StringBuffer();
    if (keyModifiers != null && !keyModifiers.equals("")) {
        contextMenuText.append(keyModifiers + "+");
    }
    contextMenuText.append(key);
    return contextMenuText.toString().equals(keyText);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:18,代码来源:JavaFxRecorderHook.java

示例15: emailcheck

import javafx.scene.input.KeyEvent; //导入依赖的package包/类
@FXML
 private void emailcheck(KeyEvent k)
 {
 String c=k.getCharacter();
if(c.equals(" "))
{
     k.consume();
}
  String EMAIL_REGEX = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$";
   if(userNameTF.getText().matches(EMAIL_REGEX))
   {
   validateFalseLabel.setVisible(false);
   validateTrueLabel.setVisible(true);
   validateTrueLabel.setText("Kindly click on Login");
   b=true;
   }
   else
   {
       validateTrueLabel.setVisible(false);
       validateFalseLabel.setVisible(true);
       validateFalseLabel.setText("Invalid E-Mail Format");
       b=false;
   }
  
      
 }
 
开发者ID:ksaluja24,项目名称:scratch-bench,代码行数:27,代码来源:KController.java


注:本文中的javafx.scene.input.KeyEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。