-
-
Notifications
You must be signed in to change notification settings - Fork 235
Description
Holding down a key in Piston will begin to generate multiple spurious input events after short delay. This behaviour is like the common "key repeat" feature found in most text areas in GUIs, but is presumably only accidentally happening in Piston, given that it makes it impossible to tell which are the actual press events, and which are repeats. (And previous discussion also suggests it is not deliberate — see below.)
Observed on Mac OS X latest (10.13.2) and previous versions. Not sure if this affects other platforms. Not sure if it's caused by Piston itself, or some underlying input library. Maybe it only shows up on some backends.
Code
extern crate piston;
extern crate piston_window;
use piston::input::*;
use piston_window::*;
fn main() {
let mut window: PistonWindow = WindowSettings::new(
"piston: unwanted key repeats",
[200, 200]
)
.exit_on_esc(true)
.build()
.unwrap();
window.set_lazy(true);
while let Some(e) = window.next() {
if let Event::Input(input) = e {
if let Input::Button(button_args) = input {
if let Button::Keyboard(key) = button_args.button {
// Hold down a key, and see the message repeated in your terminal.
println!("Key event: {:?} {:?}", key, button_args.state);
}
}
}
}
}How to reproduce
Just hold down any key, and watch the terminal output.
Output
Key event: J Press
Key event: J Release
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Release
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Press
Key event: J Release
Key event: Escape Press
Previous discussion
In a previous discussion somebody believed that they'd seen key repeat behaviour in Piston, then later concluded that they were thinking of some other library.
A relevant parallel seems generating keypress events - SDL2/piston send repeated keypress events as a convenience when the same key is being held down. (I'd argue that this behaviour is the type you don't want - since it's "overloading" an existing event rather than using a different one such as KeyRepeat.)
And later...
I was flat wrong here, keypress events do not autorepeat. Apologies, I must have been thinking about a different library in my past.
And from someone else...
I was curious about the key repeat, because I couldn't remember it.
This combined with the evidence above makes me suspect it may be a platform- or backend-specific bug. I'll try on another OS and post results here.