initial commit
This commit is contained in:
commit
bd29583097
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/target
|
||||||
|
**/*.rs.bk
|
||||||
|
Session.vim
|
236
Cargo.lock
generated
Normal file
236
Cargo.lock
generated
Normal file
@ -0,0 +1,236 @@
|
|||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.2.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytes"
|
||||||
|
version = "0.4.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "custom_derive"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "enum_derive"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "evdev-rs"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"evdev-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"nix 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "evdev-sys"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gcc"
|
||||||
|
version = "0.3.55"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ioctl-sys"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iovec"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.43"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libudev"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libudev-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libudev-sys"
|
||||||
|
version = "0.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nix"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nix"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkg-config"
|
||||||
|
version = "0.3.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rip-synergy"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"evdev-rs 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"uinput 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc_version"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "semver"
|
||||||
|
version = "0.1.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uinput"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"enum_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libudev 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"nix 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"uinput-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uinput-sys"
|
||||||
|
version = "0.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"ioctl-sys 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "void"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi"
|
||||||
|
version = "0.2.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[metadata]
|
||||||
|
"checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3"
|
||||||
|
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
|
||||||
|
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
|
||||||
|
"checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d"
|
||||||
|
"checksum bytes 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0ce55bd354b095246fc34caf4e9e242f5297a7fd938b090cadfea6eee614aa62"
|
||||||
|
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
|
||||||
|
"checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9"
|
||||||
|
"checksum enum_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "406ac2a8c9eedf8af9ee1489bee9e50029278a6456c740f7454cf8a158abc816"
|
||||||
|
"checksum evdev-rs 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba3b5ca1b2d00e3daf84e440695fa0dca344afd257cc2824683992b73a531fe4"
|
||||||
|
"checksum evdev-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8a81074f548acb44df61e332141333416b6c49db6a2034d77c3cd86f2a3bf34a"
|
||||||
|
"checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
|
||||||
|
"checksum ioctl-sys 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5e2c4b26352496eaaa8ca7cfa9bd99e93419d3f7983dc6e99c2a35fe9e33504a"
|
||||||
|
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
|
||||||
|
"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
|
||||||
|
"checksum libudev 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea626d3bdf40a1c5aee3bcd4f40826970cae8d80a8fec934c82a63840094dcfe"
|
||||||
|
"checksum libudev-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324"
|
||||||
|
"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
|
||||||
|
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
|
||||||
|
"checksum nix 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b7fd5681d13fda646462cfbd4e5f2051279a89a544d50eb98c365b507246839f"
|
||||||
|
"checksum nix 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0d95c5fa8b641c10ad0b8887454ebaafa3c92b5cd5350f8fc693adafd178e7b"
|
||||||
|
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
|
||||||
|
"checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084"
|
||||||
|
"checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac"
|
||||||
|
"checksum uinput 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b074d55c90be32a89a063fe3f944c0ceed0a8e3291369a99809f18fa326685b"
|
||||||
|
"checksum uinput-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9aabddd8174ccadd600afeab346bb276cb1db5fafcf6a7c5c5708b8cc4b2cac7"
|
||||||
|
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
||||||
|
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "rip-synergy"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["siikamiika <miika9764@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
uinput = "0.1.3"
|
||||||
|
evdev-rs = "0.1.0"
|
6
src/event.rs
Normal file
6
src/event.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub struct ThreadInputEvent {
|
||||||
|
pub typ: u32,
|
||||||
|
pub code: u32,
|
||||||
|
pub value: i32,
|
||||||
|
}
|
22
src/hw_device.rs
Normal file
22
src/hw_device.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
extern crate evdev_rs;
|
||||||
|
|
||||||
|
use std::fs::File;
|
||||||
|
|
||||||
|
pub struct HwDevice {
|
||||||
|
pub device: evdev_rs::Device,
|
||||||
|
_file: File,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HwDevice {
|
||||||
|
pub fn new(path: &str) -> Self {
|
||||||
|
let f = File::open(path).unwrap();
|
||||||
|
let mut d = evdev_rs::Device::new().unwrap();
|
||||||
|
d.set_fd(&f).unwrap();
|
||||||
|
|
||||||
|
HwDevice {
|
||||||
|
device: d,
|
||||||
|
// keep fd open
|
||||||
|
_file: f,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
84
src/main.rs
Normal file
84
src/main.rs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
extern crate uinput;
|
||||||
|
extern crate evdev_rs;
|
||||||
|
|
||||||
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
|
use evdev_rs::util::event_code_to_int;
|
||||||
|
use evdev_rs::enums::EventType::{EV_KEY, EV_REL};
|
||||||
|
|
||||||
|
mod virtual_mouse;
|
||||||
|
mod virtual_kbd;
|
||||||
|
mod hw_device;
|
||||||
|
mod event;
|
||||||
|
|
||||||
|
use self::event::ThreadInputEvent;
|
||||||
|
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let kbd_path = "/dev/input/by-id/usb-04d9_USB_Keyboard-event-kbd";
|
||||||
|
let mouse_path = "/dev/input/by-id/usb-Kingsis_Peripherals_ZOWIE_Gaming_mouse-event-mouse";
|
||||||
|
|
||||||
|
// thread-safe event queue
|
||||||
|
let queue = Arc::new(Mutex::new(VecDeque::new()));
|
||||||
|
|
||||||
|
// start a thread listening to input events for each device
|
||||||
|
for &p in [kbd_path, mouse_path].iter() {
|
||||||
|
// clone queue mutex reference for this thread
|
||||||
|
let thread_queue = queue.clone();
|
||||||
|
|
||||||
|
thread::spawn(move || {
|
||||||
|
// open device
|
||||||
|
let mut dev = hw_device::HwDevice::new(p);
|
||||||
|
// wait for device init
|
||||||
|
thread::sleep(Duration::from_millis(200));
|
||||||
|
// don't deliver events elsewhere
|
||||||
|
dev.device.grab(evdev_rs::GrabMode::Grab).unwrap();
|
||||||
|
// read events and put them to queue
|
||||||
|
loop {
|
||||||
|
let event = dev.device.next_event(evdev_rs::NORMAL | evdev_rs::BLOCKING);
|
||||||
|
match event {
|
||||||
|
Ok(e) => thread_queue.lock().unwrap().push_back(
|
||||||
|
ThreadInputEvent {
|
||||||
|
typ: e.1.event_type as u32,
|
||||||
|
code: event_code_to_int(&e.1.event_code).1,
|
||||||
|
value: e.1.value,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
Err(_) => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// init virtual devices
|
||||||
|
let mut virt_kbd = virtual_kbd::VirtualKeyboard::new("test-kbd");
|
||||||
|
let mut virt_mouse = virtual_mouse::VirtualMouse::new("test-mouse");
|
||||||
|
|
||||||
|
// read events and feed them to the virtual devices
|
||||||
|
loop {
|
||||||
|
let event = queue.lock().unwrap().pop_front();
|
||||||
|
match event {
|
||||||
|
// quit on esc
|
||||||
|
Some(e) if e.typ == EV_KEY as u32 && e.code == 1 => break,
|
||||||
|
// mouse event
|
||||||
|
Some(e) if e.typ == EV_REL as u32 || (e.code >= 272 && e.code <= 276) => {
|
||||||
|
virt_mouse.device.write(e.typ as i32, e.code as i32, e.value).unwrap();
|
||||||
|
virt_mouse.device.synchronize().unwrap();
|
||||||
|
},
|
||||||
|
// keyboard event
|
||||||
|
Some(e) if e.typ == EV_KEY as u32 => {
|
||||||
|
virt_kbd.device.write(e.typ as i32, e.code as i32, e.value).unwrap();
|
||||||
|
virt_kbd.device.synchronize().unwrap();
|
||||||
|
},
|
||||||
|
// balance responsiveness and low cpu load
|
||||||
|
None => thread::sleep(Duration::from_millis(10)),
|
||||||
|
// print unknown events
|
||||||
|
// Some(e) => println!("{} {} {}", e.typ, e.code, e.value),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
src/virtual_kbd.rs
Normal file
20
src/virtual_kbd.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
extern crate uinput;
|
||||||
|
|
||||||
|
use uinput::event::Keyboard;
|
||||||
|
|
||||||
|
pub struct VirtualKeyboard {
|
||||||
|
pub device: uinput::Device,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VirtualKeyboard {
|
||||||
|
pub fn new(name: &str) -> Self {
|
||||||
|
let virt_kbd = uinput::default().unwrap()
|
||||||
|
.name(name).unwrap()
|
||||||
|
.event(Keyboard::All).unwrap()
|
||||||
|
.create().unwrap();
|
||||||
|
|
||||||
|
VirtualKeyboard {
|
||||||
|
device: virt_kbd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
src/virtual_mouse.rs
Normal file
29
src/virtual_mouse.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
extern crate uinput;
|
||||||
|
|
||||||
|
use uinput::event::relative;
|
||||||
|
use uinput::event::controller::Mouse;
|
||||||
|
|
||||||
|
pub struct VirtualMouse {
|
||||||
|
pub device: uinput::Device,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VirtualMouse {
|
||||||
|
pub fn new(name: &str) -> Self {
|
||||||
|
let virt_mouse = uinput::default().unwrap()
|
||||||
|
.name(name).unwrap()
|
||||||
|
.event(Mouse::Left).unwrap()
|
||||||
|
.event(Mouse::Right).unwrap()
|
||||||
|
.event(Mouse::Middle).unwrap()
|
||||||
|
.event(Mouse::Side).unwrap()
|
||||||
|
.event(Mouse::Extra).unwrap()
|
||||||
|
.event(relative::Position::X).unwrap()
|
||||||
|
.event(relative::Position::Y).unwrap()
|
||||||
|
.event(relative::Wheel::Vertical).unwrap()
|
||||||
|
.event(relative::Wheel::Horizontal).unwrap()
|
||||||
|
.create().unwrap();
|
||||||
|
|
||||||
|
VirtualMouse {
|
||||||
|
device: virt_mouse
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user