Skip to content

Add support for ButtonInput<Key> #19684

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

Merged
merged 5 commits into from
Jun 18, 2025

Conversation

kristoff3r
Copy link
Contributor

@kristoff3r kristoff3r commented Jun 16, 2025

Objective

While KeyCode is very often the correct way to interact with keyboard input there are a bunch of cases where it isn't, notably most of the symbols (e.g. plus, minus, different parentheses). Currently the only way to get these is to read from EventReader<KeyboardInput>, but then you'd have to redo the ButtonInput logic for pressed/released to e.g. make zoom functionality that depends on plus/minus keys.

This has led to confusion previously, like #3278

Solution

Add a ButtonInput<Key> resource.

Testing

Modified the keyboard_input example to test it.

Open questions

I'm not 100% sure this is the right way forward, since it duplicates the key processing logic and might make people use the shorter ButtonInput<Key> even when it's not appropriate.

Another option is to add a new struct with both Key and KeyCode, and use ButtonInput with that instead. That would make it more explanatory, but that is a lot of churn.

The third alternative is to not do this because it's too niche.

I'll add more documentation and take it out of draft if we want to move forward with it.

@alice-i-cecile alice-i-cecile added A-Input Player input via keyboard, mouse, gamepad, and more X-Controversial There is active debate or serious implications around merging this PR M-Needs-Release-Note Work that should be called out in the blog due to impact S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 16, 2025
Copy link
Contributor

It looks like your PR has been selected for a highlight in the next release blog post, but you didn't provide a release note.

Please review the instructions for writing release notes, then expand or revise the content in the release notes directory to showcase your changes.

@alice-i-cecile
Copy link
Member

My initial stance on this as SME-Input is that a) we should do this and b) we need to be extremely careful about docs here.

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged S-Needs-SME Decision or review from an SME is required and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jun 16, 2025
Copy link
Contributor

@Shatur Shatur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me.

Copy link
Contributor

@IceSentry IceSentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR generally makes sense, but I think to avoid any footguns the docs of KeyCode should point to Key and explain why they might want it and the reverse should also be done. I also think Key::Character should point to KeyCode to let users know they might want to use that one instead.

Maybe we should rename Key to LogicalKey? That I don't know, but treating Key and KeyCode on the same level makes sense to me.

@kristoff3r
Copy link
Contributor Author

I think this PR generally makes sense, but I think to avoid any footguns the docs of KeyCode should point to Key and explain why they might want it and the reverse should also be done. I also think Key::Character should point to KeyCode to let users know they might want to use that one instead.

Maybe we should rename Key to LogicalKey? That I don't know, but treating Key and KeyCode on the same level makes sense to me.

Yeah definitely the docs need to be improved, I'll do that soon and take the PR out of draft when I'm done.

Key and KeyCode are both copy pasted from winit, so we shouldn't change the name unless we have a very good reason.

@kristoff3r kristoff3r marked this pull request as ready for review June 18, 2025 08:19
@kristoff3r
Copy link
Contributor Author

@alice-i-cecile I added docs and release notes, let me know if you want more docs in other areas as well.

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with the level of clarity here, and I think we should expose this.

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Contentious There are nontrivial implications that should be thought through and removed X-Controversial There is active debate or serious implications around merging this PR S-Needs-SME Decision or review from an SME is required labels Jun 18, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 18, 2025
Merged via the queue into bevyengine:main with commit 2119838 Jun 18, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more M-Needs-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Contentious There are nontrivial implications that should be thought through
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants