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!

  • Thanks your your reply. However, this does not seem to be the problem. I tried with your code and still not working...the problem is the duration the buttom button 4 is pressed. If pressed just once, quick, does not work, if pressed once long (push, wait, release) it works...

  • 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!
  • 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).

    ...

    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 think the problem here is with the use of WatchUi.SLIDE_BLINK. According to the docs (https://developer.garmin.com/connect-iq/api-docs/Toybox/WatchUi.html) WatchUi.SLIDE_BLINK is only available for devices with CIQ 3.1.0 and higher.
    If you need to support other devices, you'll have to use this conditionally. e.g.
    WatchUi.pushView(
      new $.Steps_Battle_AttackView(),
      new $.EntryMenuDelegate(),
      WatchUi has :SLIDE_BLINK ? WatchUi.SLIDE_BLINK : WatchUi.SLIDE_IMMEDIATE
    );
  • 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!