以下のようにKeyEvent
ハンドラを設定すると、動作は期待どおりで、大文字と文字または文字ではないAscii文字についてはOracleのマニュアルのようになります。小文字の不思議なKeyEvent処理
しかし、小文字の場合、文字を入力するときにCtrlキーを押したままにすると、EventHandler
はキー押しを登録できないようです。
これは、Q、q、$、Ctrl + Q、Ctrl + q、Ctrl + $を順番に入力すると、下の出力に表示されます。
誰でもこの現象を解明できますか?何か不足していますか?私は検索しましたが、この質問に対する他の参照は見つかりませんでした。
import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
import javafx.event.*;
import javafx.scene.input.KeyEvent;
// Test handling keypresses of upper and lower case letter, and non-alphameric ascii symbol,
// to see if any difference exists when Ctrl is held down
// between the handling for (ev.isShortcutDown()) and (ev.isMetaDown() || ev.isControlDown())
// and between the three character types
// Program to be tested by typing, in sequence,
// Q q $ Ctrl+Q Ctrl+q Ctrl+$
public class TestHandlingKeyEvents extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(Stage stage) throws Exception {
Scene scene = new Scene(new Group());
stage.setScene(scene);
EventHandler<KeyEvent> handleUserTyping = ev -> {
String charTyped = ev.getCharacter();
switch (charTyped) {
case "Q": // quit
System.out.println("\nQ typed ");
if (ev.isShortcutDown())
System.out.println("with Shortcut down ");
if (ev.isMetaDown() || ev.isControlDown())
System.out.println("with Meta or Ctrl down ");
break;
case "q": // complete reset
System.out.println("\nq typed ");
if (ev.isShortcutDown())
System.out.println("with Shortcut down ");
if (ev.isMetaDown() || ev.isControlDown())
System.out.println("with Meta or Ctrl down ");
break;
case "$": // back to last view
System.out.println("\n$ typed ");
if (ev.isShortcutDown())
System.out.println("with Shortcut down ");
if (ev.isMetaDown() || ev.isControlDown())
System.out.println("with Meta or Ctrl down ");
break;
}
};
scene.setOnKeyTyped(handleUserTyping);
stage.show();
}
}
そして出力:
[email protected]:/java$ java TestHandlingKeyEvents
Q typed
q typed
$ typed
Q typed
with Shortcut down
with Meta or Ctrl down
$ typed
with Shortcut down
with Meta or Ctrl down
[email protected]:/java$