2 回答
TA贡献1725条经验 获得超7个赞
我可以重现这种行为。如果您在舞台上添加一个,EventHandler
您可以清楚地看到问题。
stage.addEventFilter(KeyEvent.KEY_TYPED, ev -> { System.out.println("Key typed: " + ev.getCharacter()); });
输出:
Key typed: ¨ Key typed: Ι Key typed: ¨ Key typed: ι
我们对此无能为力,只能提交错误报告。
我不知道您是否可以在KeyEvents
发送这些键之前捕获键入的键,但您可以在阶段级别过滤它们。
stage.addEventFilter(KeyEvent.KEY_TYPED, new KeyTypedListener());
这不是很好,而是一种更“全球”的改变行为的方式。
public class KeyTypedListener implements EventHandler<KeyEvent> {
private boolean disabled = false;
private Map<String, String> charCombinations = new HashMap<>();
private KeyEvent pendingEvent;
public KeyTypedListener() {
charCombinations.put("¨ι", "ϊ");
charCombinations.put("¨Ι", "Ϊ");
}
@Override
public void handle(final KeyEvent event) {
if (disabled || event.getCharacter() == null
|| event.getCharacter().length() != 1) {
return;
}
final String typed = event.getCharacter();
if (pendingEvent == null && isCombiCharacter(typed)) {
pendingEvent = event.copyFor(event.getSource(), event.getTarget());
event.consume();
} else if (pendingEvent != null) {
String combination =
charCombinations.get(pendingEvent.getCharacter() + typed);
if (combination == null) {
disabled = true;
fireEvent(pendingEvent);
disabled = false;
pendingEvent = null;
} else {
event.consume();
pendingEvent = null;
Platform.runLater(() -> {
fireEventWithCharacter(event, combination);
});
}
}
}
private boolean isCombiCharacter(final String character) {
return "¨".equals(character);
}
private void fireEvent(final KeyEvent event) {
Event.fireEvent(event.getTarget(), event);
}
private void fireEventWithCharacter(final KeyEvent event,
final String character) {
fireEvent(new KeyEvent(event.getSource(), event.getTarget(),
event.getEventType(), character, "", KeyCode.UNDEFINED,
event.isShiftDown(), event.isControlDown(), event.isAltDown(),
event.isMetaDown()));
}
}
当然你也可以创建一个新的EventDispatcher.
TA贡献1895条经验 获得超3个赞
我认为这是希腊键盘的问题。我尝试使用其他文本字段(Opera 搜索栏、Google 搜索栏等),但无法写出这个字符。您只能使用 Alt+0239 组合来编写此内容。您可以尝试使用“field2.setOnKeyPressed()”创建组合。
添加回答
举报