Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space triggers the last pressed button #1825

Open
raresn opened this issue Jun 27, 2023 · 2 comments
Open

Space triggers the last pressed button #1825

raresn opened this issue Jun 27, 2023 · 2 comments

Comments

@raresn
Copy link

raresn commented Jun 27, 2023

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
Copy link

@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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants