我使用以下代码检查是否单击了某个键:
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// Little method to allow the sound to be changed
if(keyCode == 24 || keyCode == 25) {
return false;
}
if(event.getAction() == KeyEvent.ACTION_DOWN) {
// if(resetKeyPress != true) {
this.keyCode = keyCode;
// resetKeyPress = true;
if(this.logGameEngineInputLog == true) {
gameEngineLog.d(classTAG, "Pressed down " + this.keyCode);
}
// }
}
else if(event.getAction() == KeyEvent.ACTION_UP){
//waitUntilReleased = false;
//this.changeKeyCode(null);
if(this.logGameEngineInputLog == true) {
gameEngineLog.d(classTAG, "Released key " + this.keyCode);
}
this.keyCode = null;
// resetKeyPress = false;
}
return true;
}
当我长时间点击一个按钮时,它一直说按下了一个按钮,但是过了一会儿它说键已被释放,即使我仍然按住键。为什么要这样做?有没有办法防止这种情况?这是由 Android 操作系统故意完成的,如果是,为什么?