将一个KeyListener
类添加到一个org.eclipse.swt.widgets.Text
类。当我输入'a'
时,我得到了多个 keyEvents。我只期待一个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