-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Opening a Window on keyboard_input.just_pressed
makes it trigger again
#12273
Comments
When a new window is spawned, winit sends a key released event for to the old window and a key pressed event to the new one (tested without Bevy too). I'm not sure if that's intentional. If not, we need to crate an issue in the winit repo; if it is, we need to work around this by ignoring key release events if in the same frame a window has been created and a key press event for the same button gets received. Edit: These event happen when a window loses/gains focus. They have the So We could just ignore synthetic events ourselves. The problem is that the button state can change while no Bevy window is focused. I think it might be best to wait until Bevy gains focus again to check whether to emit those events, and maybe keep the current behavior as a separate function. |
# Objective `ButtonInput<KeyCode>` documentation is currently incorrect/incomplete, see #12273. ## Solution Fix the documentation. I think in the future we should also stop triggering `just_pressed`/`just_released` when focus switches between two Bevy windows, as those functions are independent of the window. It could also make sense to add individual `ButtonInput<KeyCode>`s per window. --------- Co-authored-by: Mateusz Wachowiak <[email protected]>
# Objective `ButtonInput<KeyCode>` documentation is currently incorrect/incomplete, see bevyengine#12273. ## Solution Fix the documentation. I think in the future we should also stop triggering `just_pressed`/`just_released` when focus switches between two Bevy windows, as those functions are independent of the window. It could also make sense to add individual `ButtonInput<KeyCode>`s per window. --------- Co-authored-by: Mateusz Wachowiak <[email protected]>
…t_released (#12372) # Objective Fix #12273 ## Solution – Only emit `KeyboardFocusLost` when the keyboard focus is lost – ignore synthetic key releases too, not just key presses (as they're already covered by `KeyboardFocusLost`) --- ## Changelog ### Fixed - Don't trigger `ButtonInput<KeyCode>::just_pressed`/`just_released` when spawning a window/focus moving between Bevy windows
Bevy version
0.13
[Optional] Relevant system information
Windows 11
What you did
I made a system similar to the one in the
keyboard_input
example. But on the check whether the keyA
was just pressed, I then spawn a window.What went wrong
It spams opening new windows, the
just_pressed
is held for multiple frames.I think this happens because it opens a new window, thus the focus is on the new window and the press counts as a new press?
The text was updated successfully, but these errors were encountered: