Skip to content

Commit e727170

Browse files
authored
Expose Winit's KeyEvent::repeat in KeyboardInput (#14161)
# Objective I would like to know if an event was emitted because of "key repeats" or not. Winit already exposes this information, but it isn't sent along by Bevy, which this PR intends to address. ## Solution Expose [`winit::event::KeyEvent::repeat`](https://docs.rs/winit/0.30.3/winit/event/struct.KeyEvent.html#structfield.repeat) in [`bevy::input::keyboard::KeyboardInput`](https://docs.rs/bevy/0.14.0/bevy/input/keyboard/struct.KeyboardInput.html). ## Testing Just hold any regular key down and only the first event should have `KeyboardInput::repeat` set to `false`. Most OSs have "key repeat" enabled by default. --- ## Changelog - Added `KeyboardInput::repeat` signifying if this event was sent in response to a "key repeat" event or not.
1 parent 276815a commit e727170

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

crates/bevy_input/src/keyboard.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ pub struct KeyboardInput {
102102
pub logical_key: Key,
103103
/// The press state of the key.
104104
pub state: ButtonState,
105+
/// On some systems, holding down a key for some period of time causes that key to be repeated
106+
/// as though it were being pressed and released repeatedly. This field is [`true`] if this
107+
/// event is the result of one of those repeats.
108+
pub repeat: bool,
105109
/// Window that received the input.
106110
pub window: Entity,
107111
}

crates/bevy_winit/src/converters.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub fn convert_keyboard_input(
1717
state: convert_element_state(keyboard_input.state),
1818
key_code: convert_physical_key_code(keyboard_input.physical_key),
1919
logical_key: convert_logical_key(&keyboard_input.logical_key),
20+
repeat: keyboard_input.repeat,
2021
window,
2122
}
2223
}

0 commit comments

Comments
 (0)