1

Possible Duplicate:
OnTouchListener, ACTION_UP fires automatically after 30 second timeout

I use the following code to check if a key is clicked:

@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;
    }

When I click a button for a long time, it keeps on saying a button is pressed, however after a while it says the key has been released, even though I'm still holding down the key. Why is it doing this? Is there a way to prevent this? Is this being done on purpose by the Android OS, if so, why?

Community
  • 1
  • 1
Luke Taylor
  • 9,481
  • 13
  • 41
  • 73
  • Might be similar, however I use the OnKeyListener. – Luke Taylor Sep 16 '12 at 19:19
  • Is this for a motorola device? If you follow the link on the duplicate question they seem to consider this a 'feature'. Doesn't sound like there is any workaround. – Tim Sep 16 '12 at 19:19

1 Answers1

0

We don't know what is the type which handle this event : View, Activity ?

In the View case, onKey handles hardware key events only (according to the documentation : Android Reference - View.KeyEventListener)

Moreover, if you take a look to this thread : How to differentiate between long key press and regular key press?, you can see an implementation of the Activity.onKeyLongPress() method, and the errors you should not make.

Community
  • 1
  • 1
mithrop
  • 3,283
  • 2
  • 21
  • 40