feathersui-starling icon indicating copy to clipboard operation
feathersui-starling copied to clipboard

Space triggers the last pressed button

Open raresn opened this issue 1 year ago • 2 comments

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 ? :)

raresn avatar Jun 27 '23 13:06 raresn

@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.

Adrian-S avatar Jun 27 '23 15:06 Adrian-S

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.

joshtynjala avatar Jun 27 '23 15:06 joshtynjala