gpt4 book ai didi

java - 仅输入一个字符时 KeyAdapter 发生多个按键事件

转载 作者:行者123 更新时间:2023-12-01 14:53:26 24 4
gpt4 key购买 nike

KeyListener 类添加到 org.eclipse.swt.widgets.Text 类。当我输入 'a' 时,我得到多个 keyEvent。我只期待一个关键事件。这是为什么。

text.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent keyEvent) {
super.keyReleased(keyEvent);
logger.log(Level.INFO, "keyEvent-->" + "\n" +
"character :" + keyEvent.character + "\n" +
"code :" + keyEvent.keyCode + "\n" +
"location :" + keyEvent.keyLocation + "\n" +
"stateMask :" + keyEvent.stateMask + "\n" +
"time :" + keyEvent.time + "\n" +
"hashCode :" + keyEvent.hashCode() + "\n" +
"data :" + keyEvent.data + "\n" +
"doit :" + keyEvent.doit + "\n");
}
});

输出(按键盘上的“a”一次后):

keyReleased
INFO: keyEvent-->
character :a
code :97
location :0
stateMask :0
time :15626510
hashCode :692735
data :null
doit :true

keyReleased
INFO: keyEvent-->
character :a
code :97
location :0
stateMask :0
time :15626510
hashCode :32967617
data :null
doit :true

keyReleased
INFO: keyEvent-->
character :a
code :97
location :0
stateMask :0
time :15626510
hashCode :2412752
data :null
doit :true

keyReleased
INFO: keyEvent-->
character :a
code :97
location :0
stateMask :0
time :15626510
hashCode :17374804
data :null
doit :true

keyReleased
INFO: keyEvent-->
character :a
code :97
location :0
stateMask :0
time :15626510
hashCode :27668426
data :null
doit :true

keyReleased
INFO: keyEvent-->
character :a
code :97
location :0
stateMask :0
time :15626510
hashCode :25933099
data :null
doit :true

最佳答案

您可能在该组件的生命周期内添加了多个 KeyAdapter - 尝试通过查看 getKeyListeners().length 返回的内容进行检查。

关于java - 仅输入一个字符时 KeyAdapter 发生多个按键事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14570882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com