mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
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:⌨️: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.
This commit is contained in:
parent
276815a9a0
commit
e7271709b2
2 changed files with 5 additions and 0 deletions
|
@ -102,6 +102,10 @@ pub struct KeyboardInput {
|
||||||
pub logical_key: Key,
|
pub logical_key: Key,
|
||||||
/// The press state of the key.
|
/// The press state of the key.
|
||||||
pub state: ButtonState,
|
pub state: ButtonState,
|
||||||
|
/// On some systems, holding down a key for some period of time causes that key to be repeated
|
||||||
|
/// as though it were being pressed and released repeatedly. This field is [`true`] if this
|
||||||
|
/// event is the result of one of those repeats.
|
||||||
|
pub repeat: bool,
|
||||||
/// Window that received the input.
|
/// Window that received the input.
|
||||||
pub window: Entity,
|
pub window: Entity,
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ pub fn convert_keyboard_input(
|
||||||
state: convert_element_state(keyboard_input.state),
|
state: convert_element_state(keyboard_input.state),
|
||||||
key_code: convert_physical_key_code(keyboard_input.physical_key),
|
key_code: convert_physical_key_code(keyboard_input.physical_key),
|
||||||
logical_key: convert_logical_key(&keyboard_input.logical_key),
|
logical_key: convert_logical_key(&keyboard_input.logical_key),
|
||||||
|
repeat: keyboard_input.repeat,
|
||||||
window,
|
window,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue