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 Comment Children
  • You may want to only do "return true" for keys you handled and "return false" for the others.

  • Seems that the following code works well:

    public function onKeyReleased(evt as KeyEvent) as Boolean {
            var key = (evt.getKey());
            if (key == WatchUi.KEY_ENTER) {
                onSelect_Battle();
            }
            return true;
        }
  • I am using the Forerunner 645m, but happens the same in several devices. What do you mean with "to return a value in your onKey function"?

    If I do:

    function onKey(keyEvent) {
            if (keyEvent.getKey() == 13) {slide_left();}
            if (keyEvent.getKey() == WatchUi.KEY_ENTER) {onSelect_Battle();}
        }
    public function onSelect_Battle() as Boolean {
            System.println("Activated")
            return true;
        }
     
    It works well with "long" and "short" press. I do not know why with if (keyEvent.getKey() == WatchUi.KEY_ENTER) {onSelect_Battle();} it does not work with short press.
     
    If istead of KEY_ENTER ( number 4) I use aother button, the 13 for example it works perfect, but I need to use the 4 (key_Enter).
    Might be the sim that is not working properly?
    Thanks!
  • You need to return a value in your onKey function.  You also may see things on a real device you don't see in the sim.  On something like a venu2, long press of the upper right botton will take you to the controals screen/

    You really need to say what device you are using in the sim.

  • Thank you Jim for your answer. I have already checked the input example. Button 4 is KEY_ENTER. There is no difference if short or long pressed, just the pressed / not pressed status, but does the same. I tried with several Forerunner and other watches devices with buttons.

    The code is:

    function onKey(keyEvent) {
            if (keyEvent.getKey() == 13) {slide_left();}
            if (keyEvent.getKey() == WatchUi.KEY_ENTER) {onSelect_Battle();}
        }
    public function onSelect_Battle() as Boolean {
            WatchUi.pushView(new $.Steps_Battle_AttackView(), new $.EntryMenuDelegate(), WatchUi.SLIDE_BLINK);
            return true;
        }

    When pushed fast the KEY_ENTER, gives the error, if pushed "slow" it works. Similar response if: if (keyEvent.getKey() == 4) {onSelect_Battle();}

    If I change to function to the following one, it works for short and long pressed.

    public function onSelect_Battle() as Boolean {
            System.println("Activated")
            return true;
        }
    I am totally blocked.
    Thanks!