Avg. Rating 3.7

Problem

When a user presses the "win" key (key with Windows logo), the list component is scrolling by 1 position, and then opens a windows start dialog.

Solution

Make a handler for "win" key on application start-up.

Detailed explanation

After looking to a ListBase class keyDownHandler function, I found a function witch is called as a default for switch..case for keyCode. This function is called findKey .

Here is the comment from developers for this function:

 

/**
  *  Tries to find the next item in the data provider that
  *  starts with the character in the <code>eventCode</code> parameter.
  *  You can override this to do fancier typeahead lookups. The search
  *  starts at the <code>selectedIndex</code> location; if it reaches
  *  the end of the data provider it starts over from the beginning.
  *
  *  @param eventCode The key that was pressed on the keyboard.
  *  @return <code>true</code> if a match was found.
  */

So, when user press the "win" key, the keyCode switch calls the findKey() function ("win" key keyCode is 91), and List component trying to scroll to item with char getted from keyCode 91 ( symbol [ ). So my fix is to handle KeyboardEvent.KEY_DOWN event, to prevent event from "win" key propagation.

 

// Add this handler on creationComplete of your application.
Application.application.addEventListener(KeyboardEvent.KEY_DOWN,
    handleWindows, false, 1000);

// Use this keyDown event handler.
private function handleWindows (event:KeyboardEvent): void {
  if (event.keyCode == 91) {
    event.stopImmediatePropagation();
    event.stopPropagation();
  }
}
Report abuse

Related recipes