Error thrown on .getKey(). How to use the KeyEvent.getKey() to determine which button is pressed?

I am trying to build an app, and I am on the latest SDK. I'm trying to access the key controls with KeyEvent (and not just the onSelect behavior because I would like to use the onTap and onSwipe as well) but I get this error below. I have tried already many options, including using the InputDelegate instead but I cannot get it work appropriate. 

If I store keyEvent.getKey() in a variable first, it doesn't throw an error at that step. But printing that variable - logically - still gives me the same error. Also, for example, printing the keyEvent.getKey() == 1 only return false (for a range of numbers). As I am new, I would like to print the values so I know what I am dealing with.

Below a sample of the code (which is directly from the API docs), is there anyone who knows how to get this part of the code going? 

Thank you!

  • This feels like a type checker bug to me, but I was able to reproduce the error you're getting with the latest non-beta SDK (4.1.7) and the Selectable sample:

        public function onKey(evt as KeyEvent) as Boolean {
            var key = evt.getKey();
            System.println(key); // <= added this line which doesn't compile
    

    One workaround is to use key.toString() - the following line compiles and runs as expected:

    System.println(key.toString());

    I think it's a type checker bug because:

    - the code builds and runs fine when type checking is disabled

    - WatchUi.Key is actually a Lang.Number, which inherits from Lang.Object.

  • That explains! The tostring workaround will do just fine for now. Thank you. This has been maddening me for days Slight smile