Formated documents
This commit is contained in:
13
src/main.rs
13
src/main.rs
@@ -35,8 +35,7 @@ fn enumerate_keyboards() -> Vec<PathBuf> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
async fn find_target_keyboard(device_paths: &Vec<PathBuf>) -> Option<Device>{
|
||||
|
||||
async fn find_target_keyboard(device_paths: &Vec<PathBuf>) -> Option<Device> {
|
||||
let (tx, mut rx): (Sender<PathBuf>, Receiver<PathBuf>) = channel(1);
|
||||
|
||||
let mut handles = vec![];
|
||||
@@ -62,24 +61,19 @@ async fn find_target_keyboard(device_paths: &Vec<PathBuf>) -> Option<Device>{
|
||||
|
||||
#[tokio::main(flavor = "local")]
|
||||
async fn main() {
|
||||
|
||||
|
||||
let devices_paths = enumerate_keyboards();
|
||||
|
||||
println!("Found the following devices");
|
||||
for path in &devices_paths {
|
||||
if let Ok(d) = Device::open(path){
|
||||
if let Ok(d) = Device::open(path) {
|
||||
println!("\t{} ({})", d.name().unwrap_or("null"), path.display())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
let Some(kb) = find_target_keyboard(&devices_paths).await else {
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
let Ok(mut kb) = kb.into_event_stream() else {
|
||||
return;
|
||||
};
|
||||
@@ -97,9 +91,8 @@ async fn main() {
|
||||
|
||||
match kb.device_mut().ungrab() {
|
||||
Err(err) => println!("Failed to release device: {err}"),
|
||||
_ => ()
|
||||
_ => (),
|
||||
};
|
||||
|
||||
println!("Device released");
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use evdev::uinput::VirtualDevice;
|
||||
use evdev::{
|
||||
AbsInfo, AbsoluteAxisCode, AttributeSet, EventStream, EventType, InputEvent, KeyCode, UinputAbsSetup
|
||||
AbsInfo, AbsoluteAxisCode, AttributeSet, EventStream, EventType, InputEvent, KeyCode,
|
||||
UinputAbsSetup,
|
||||
};
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(PartialEq, Debug, Clone, Copy)]
|
||||
#[repr(u8)]
|
||||
pub enum Direction {
|
||||
Up = 0,
|
||||
@@ -66,8 +66,6 @@ impl VirtualGamepad {
|
||||
dpad_bindings.insert(KeyCode::KEY_F.code(), Direction::Right);
|
||||
dpad_bindings.insert(KeyCode::KEY_W.code(), Direction::Left);
|
||||
|
||||
|
||||
|
||||
let ui = VirtualDevice::builder()
|
||||
.unwrap()
|
||||
.name(&name)
|
||||
@@ -86,7 +84,6 @@ impl VirtualGamepad {
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
|
||||
VirtualGamepad {
|
||||
ui,
|
||||
btn_bindings,
|
||||
|
||||
Reference in New Issue
Block a user