【发布时间】:2017-12-05 03:35:51
【问题描述】:
我在 javafx 2.0 中处理 KeyEvent 时遇到以下问题。 start 方法中的这段代码:
scene.addEventHandler(KeyEvent.ANY, e -> System.out.format(
"Type: {%s},\tCode: {%s},\tchar: {%s}%n",
e.getEventType(), e.getCode(), e.getCharacter());
);
产生:
Type: {KEY_PRESSED}, Code: {A}, char: {
Type: {KEY_TYPED}, Code: {UNDEFINED}, char: {a}
Type: {KEY_RELEASED}, Code: {A}, char: {
(与其他键和方法相同e.setOnKey{Pressed, Released, Typed}())
看起来e.getCharacter() 返回'\0'。问题出在哪里?在我的应用程序中,我需要一次获取键入键的代码和值。有趣的是,几天前,KeyEvent.KEY_PRESSED 的构造运行良好。
用例: 我正在从条形码扫描仪扫描键盘输入,它以 enter 结束每个代码(我必须与其他字符区分开来)。
【问题讨论】:
标签: java user-interface events javafx