feathersui-starling
feathersui-starling copied to clipboard
Space triggers the last pressed button
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 ? :)
@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.
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
.