mouse_keyboard_input/
lib.rs1#[macro_use]
2extern crate ioctl_sys as ioctl;
3extern crate libc;
4extern crate nix;
5extern crate crossbeam_channel;
6
7use libc::timeval;
8use std::mem;
9
10#[cfg(target_arch = "arm")]
11macro_rules! uin {
12 (write $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
13 pub unsafe fn $name(fd: i32, val: $ty) -> i32 {
14 ioctl::ioctl(fd, (iow!($ioty, $nr, mem::size_of::<$ty>()) as u64).try_into().unwrap(), val)
15 }
16 );
17}
18
19#[cfg(not(target_arch = "arm"))]
20macro_rules! uin {
21 (write $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
22 pub unsafe fn $name(fd: i32, val: $ty) -> i32 {
23 ioctl::ioctl(fd, iow!($ioty, $nr, mem::size_of::<$ty>()) as u64, val)
24 }
25 );
26}
27
28
29pub mod key_codes;
30mod virtual_device;
31mod utils;
32
33pub use crate::key_codes::*;
34pub use virtual_device::*;
35
36pub const UINPUT_MAX_NAME_SIZE: usize = 80;
37
38
39#[derive(Clone, Copy)]
40#[repr(C)]
41pub struct input_event {
42 pub time: timeval,
43 pub kind: u16,
44 pub code: u16,
45 pub value: i32,
46}
47
48#[derive(Debug, Clone, Copy)]
49#[repr(C)]
50pub struct input_id {
51 pub bustype: u16,
52 pub vendor: u16,
53 pub product: u16,
54 pub version: u16,
55}
56
57#[derive(Debug)]
58#[repr(C)]
59pub struct uinput_user_dev {
60 pub name: [i8; UINPUT_MAX_NAME_SIZE as usize],
61 pub id: input_id,
62
63 pub ff_effects_max: u32,
64 pub absmax: [i32; ABS_CNT as usize],
65 pub absmin: [i32; ABS_CNT as usize],
66 pub absfuzz: [i32; ABS_CNT as usize],
67 pub absflat: [i32; ABS_CNT as usize],
68}
69
70ioctl!(none ui_dev_create with b'U', 1);
86ioctl!(none ui_dev_destroy with b'U', 2);
87
88uin!(write ui_set_evbit with b'U', 100; i32);
89uin!(write ui_set_keybit with b'U', 101; i32);
90uin!(write ui_set_relbit with b'U', 102; i32);
91uin!(write ui_set_absbit with b'U', 103; i32);
92uin!(write ui_set_mscbit with b'U', 104; i32);
93uin!(write ui_set_ledbit with b'U', 105; i32);
94uin!(write ui_set_sndbit with b'U', 106; i32);
95uin!(write ui_set_ffbit with b'U', 107; i32);
96uin!(write ui_set_phys with b'U', 108; *const i8);
97uin!(write ui_set_swbit with b'U', 109; i32);
98uin!(write ui_set_propbit with b'U', 110; i32);
99
100ioctl!(read ui_get_version with b'U', 45; u32);