need to add gamepad events
This commit is contained in:
30
src/main.rs
30
src/main.rs
@@ -36,6 +36,7 @@ use crate::util::timer::Timer;
|
||||
use crate::util::vertex::{TextureVertex3D, VertexTypes};
|
||||
use crate::vkprocessor::VkProcessor;
|
||||
use std::path::Path;
|
||||
use gilrs::{Gilrs, Button, Event as GilEvent};
|
||||
|
||||
pub mod util;
|
||||
pub mod vkprocessor;
|
||||
@@ -144,17 +145,14 @@ pub fn main() {
|
||||
// while (accumulator_time - step_size) >= step_size {
|
||||
// accumulator_time -= step_size;
|
||||
// }
|
||||
|
||||
let mut gilrs = Gilrs::new().unwrap();
|
||||
// Iterate over all connected gamepads
|
||||
for (_id, gamepad) in gilrs.gamepads() {
|
||||
println!("{} is {:?}", gamepad.name(), gamepad.power_info());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let mut active_gamepad = None;
|
||||
|
||||
// Events loop is borrowed from the surface
|
||||
events_loop.run(move |event, _, control_flow| {
|
||||
@@ -183,6 +181,18 @@ pub fn main() {
|
||||
compu_frame);
|
||||
}
|
||||
|
||||
while let Some(GilEvent { id, event, time }) = gilrs.next_event() {
|
||||
println!("{:?} New event from {}: {:?}", time, id, event);
|
||||
active_gamepad = Some(id);
|
||||
}
|
||||
|
||||
// You can also use cached gamepad state
|
||||
if let Some(gamepad) = active_gamepad.map(|id| gilrs.gamepad(id)) {
|
||||
if gamepad.is_pressed(Button::South) {
|
||||
println!("Button South is pressed (XBox - A, PS - X)");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Event::DeviceEvent { event: DeviceEvent::Key(keyboard_input), .. } => {
|
||||
match keyboard_input.virtual_keycode.unwrap() {
|
||||
|
||||
Reference in New Issue
Block a user