Acknowledged

keyEvent.getKey() == 4 short vrs long pressed

Hi! I have the following problem, you might know the reason/solution.

I have the following code line:  if (keyEvent.getKey() == 4) {onSelect_lauch();}

I found that, in the simulator, for several devices, when I press the "Start-Stop buttom" (Key 4), if I press it long (not just one click but a "long" click), it launches properly the function but if I press it short, I gives me the typical error "Symbol Not found Error". It is an App (not a widget).

Error: Symbol Not Found Error

Details: Failed invoking <symbol>

Stack:

Do you know why and how to solve it?

Thanks!

Parents
  • You are right, good comment, I have also added it to not block older devices. Regarding the line thar is crashing, how could I know it? The Stack: line is empy...

    Oh interesting. I didn’t realize that was literally the whole error message.

    If I have a chance I’ll see if I can reproduce this problem in the sim. Jim did correctly point out that you’re supposed to return true in your onKey() event handler if you handle the key, and false otherwise.

    e.g.

    function onKey(keyEvent) {
      var key = keyEvent.getKey();
      if (key == 13) {
        slide_left();
        return true;
      }
      if (key == WatchUi.KEY_ENTER) {
        onSelect_Battle();
        return true;
      }
      return false;  
    }
    

Comment
  • You are right, good comment, I have also added it to not block older devices. Regarding the line thar is crashing, how could I know it? The Stack: line is empy...

    Oh interesting. I didn’t realize that was literally the whole error message.

    If I have a chance I’ll see if I can reproduce this problem in the sim. Jim did correctly point out that you’re supposed to return true in your onKey() event handler if you handle the key, and false otherwise.

    e.g.

    function onKey(keyEvent) {
      var key = keyEvent.getKey();
      if (key == 13) {
        slide_left();
        return true;
      }
      if (key == WatchUi.KEY_ENTER) {
        onSelect_Battle();
        return true;
      }
      return false;  
    }
    

Children