feathersui / feathersui-starling

User interface components for Starling Framework and Adobe AIR
https://feathersui.com/learn/as3-starling/
Other
914 stars 386 forks source link

Space triggers the last pressed button #1825

Open raresn opened 1 year ago

raresn commented 1 year ago

I can't believe we didn't notice this so far, but somehow when space is pressed, it triggers the last pressed button in our windows app. Any clue on how to disable this behaviour? Enter key does not do this. @joshtynjala ? :)

Adrian-S commented 1 year ago

@joshtynjala We found a solution that works for buttons and allows inputs to work too:

this._starling.nativeStage.addEventListener(KeyboardEvent.KEY_DOWN, disableSpaceKey, true, 1);
//....
protected function disableSpaceKey(event:KeyboardEvent):void
{
    if(FocusManager.focus is Button && event.keyCode == Keyboard.SPACE)
    {
        event.preventDefault();
        event.stopPropagation();
        event.stopImmediatePropagation();
    }
}

However, it seams a bit radical.

Setting FocusManager.focus = null on all trigger events also works, but seams wrong. Since keyToTrigger is protected, extending all buttons may also work, but is a lot of work.

In the future we might want to add full keyboard navigation.

Any other suggestion is more than welcomed. Thanks.

joshtynjala commented 1 year ago

If space is triggering a button, it's because the button has focus. If you're using the FocusManager, you can clear the focus with FocusManager.focus = null at any time. If you're not using the FocusManager, then set stage.focus = null (or stage.focus = stage may be better sometimes) to clear focus.

If you're using the FocusManager, and you have a custom object that needs to receive focus, you can have it implement IFocusDisplayObject.