I intended to build a project that requires listening to key-pressed and key-released events and was using crate piston, but found it wired to require a window, and it can only detect events within the window. In the project a window limits the listener and is useless, so how can I detect keyboard events without a window?
the listener with a window:
use piston::WindowSettings;
fn main() {
let settings = WindowSettings::new("Roguelike", [0; 2]).exit_on_esc(false);
let mut window :PistonWindow= settings.build().expect("Could not create window");
let mut events = Events::new(EventSettings::new());
while let Some(e)=events.next(&mut window) {
if let Some(k) = e.button_args() {
if k.state == ButtonState::Press {
match k.button {
Button::Keyboard(Key::Up) => println!("up!"),
//...
_ => (),
}
}
}
}
}
Thank you for any thoughts!