Trait DeviceWrapper

Source
pub trait DeviceWrapper: Sized {
Show 44 methods // Required method fn raw(&self) -> *mut libevdev; // Provided methods fn enable<E: Enable>(&self, e: E) -> Result<()> { ... } fn enable_property(&self, prop: &InputProp) -> Result<()> { ... } fn enable_event_type(&self, ev_type: &EventType) -> Result<()> { ... } fn enable_event_code( &self, ev_code: &EventCode, data: Option<EnableCodeData>, ) -> Result<()> { ... } fn disable<E: Enable>(&self, d: E) -> Result<()> { ... } fn disable_event_type(&self, ev_type: &EventType) -> Result<()> { ... } fn disable_event_code(&self, code: &EventCode) -> Result<()> { ... } fn has<E: Enable>(&self, e: E) -> bool { ... } fn has_property(&self, prop: &InputProp) -> bool { ... } fn has_event_type(&self, ev_type: &EventType) -> bool { ... } fn has_event_code(&self, code: &EventCode) -> bool { ... } fn name(&self) -> Option<&str> { ... } fn phys(&self) -> Option<&str> { ... } fn uniq(&self) -> Option<&str> { ... } fn set_name(&self, field: &str) { ... } fn set_phys(&self, field: &str) { ... } fn set_uniq(&self, field: &str) { ... } fn product_id(&self) -> u16 { ... } fn vendor_id(&self) -> u16 { ... } fn bustype(&self) -> u16 { ... } fn version(&self) -> u16 { ... } fn set_product_id(&self, field: u16) { ... } fn set_vendor_id(&self, field: u16) { ... } fn set_bustype(&self, field: u16) { ... } fn set_version(&self, field: u16) { ... } fn abs_info(&self, code: &EventCode) -> Option<AbsInfo> { ... } fn set_abs_info(&self, code: &EventCode, absinfo: &AbsInfo) { ... } fn event_value(&self, code: &EventCode) -> Option<i32> { ... } fn set_event_value(&self, code: &EventCode, val: i32) -> Result<()> { ... } fn abs_minimum(&self, code: u32) -> Result<i32> { ... } fn abs_maximum(&self, code: u32) -> Result<i32> { ... } fn abs_fuzz(&self, code: u32) -> Result<i32> { ... } fn abs_flat(&self, code: u32) -> Result<i32> { ... } fn abs_resolution(&self, code: u32) -> Result<i32> { ... } fn set_abs_minimum(&self, code: u32, val: i32) { ... } fn set_abs_maximum(&self, code: u32, val: i32) { ... } fn set_abs_fuzz(&self, code: u32, val: i32) { ... } fn set_abs_flat(&self, code: u32, val: i32) { ... } fn set_abs_resolution(&self, code: u32, val: i32) { ... } fn slot_value(&self, slot: u32, code: &EventCode) -> Option<i32> { ... } fn set_slot_value( &self, slot: u32, code: &EventCode, val: i32, ) -> Result<()> { ... } fn num_slots(&self) -> Option<i32> { ... } fn current_slot(&self) -> Option<i32> { ... }
}
Expand description

Abstraction over structs which contain an inner *mut libevdev

Required Methods§

Provided Methods§

Source

fn enable<E: Enable>(&self, e: E) -> Result<()>

Forcibly enable an EventType/InputProp on this device, even if the underlying device does not support it. While this cannot make the device actually report such events, it will now return true for has().

This is a local modification only affecting only this representation of this device.

Examples found in repository?
examples/vmouse.rs (line 47)
9fn main() -> Result<(), std::io::Error> {
10    // Parse command line arguments
11    let mut args = std::env::args();
12
13    if args.len() != 2 {
14        let n = args.nth(0).unwrap();
15        println!("Usage: `{} DEVICE`, eg. `{} /dev/input/event13`", n, n);
16        std::process::exit(1);
17    }
18
19    let device = &args.nth(1).unwrap();
20
21    // Connect to real keyboard
22    let f = File::open(device)?;
23    let d = Device::new_from_file(f)?;
24
25    if let Some(n) = d.name() {
26        println!(
27            "Connected to device: '{}' ({:04x}:{:04x})",
28            n,
29            d.vendor_id(),
30            d.product_id()
31        );
32    }
33
34    // Create virtual device
35    let u = UninitDevice::new().unwrap();
36
37    // Setup device
38    // per: https://01.org/linuxgraphics/gfx-docs/drm/input/uinput.html#mouse-movements
39
40    u.set_name("Virtual Mouse");
41    u.set_bustype(BusType::BUS_USB as u16);
42    u.set_vendor_id(0xabcd);
43    u.set_product_id(0xefef);
44
45    // Note mouse keys have to be enabled for this to be detected
46    // as a usable device, see: https://stackoverflow.com/a/64559658/6074942
47    u.enable(EventCode::EV_KEY(EV_KEY::BTN_LEFT))?;
48    u.enable(EventCode::EV_KEY(EV_KEY::BTN_RIGHT))?;
49
50    u.enable(EventCode::EV_REL(EV_REL::REL_X))?;
51    u.enable(EventCode::EV_REL(EV_REL::REL_Y))?;
52
53    u.enable(EventCode::EV_SYN(EV_SYN::SYN_REPORT))?;
54
55    // Attempt to create UInputDevice from UninitDevice
56    let v = UInputDevice::create_from_device(&u)?;
57
58    loop {
59        // Fetch keyboard events
60        let (_status, event) = d.next_event(ReadFlag::NORMAL | ReadFlag::BLOCKING)?;
61
62        // Map these to mouse events
63        println!("Event: {:?}", event);
64
65        // Map direction keys to mouse events
66        let e = match event.event_code {
67            EventCode::EV_KEY(EV_KEY::KEY_RIGHT) => Some((EV_REL::REL_X, MOUSE_STEP_X)),
68            EventCode::EV_KEY(EV_KEY::KEY_LEFT) => Some((EV_REL::REL_X, -MOUSE_STEP_X)),
69            EventCode::EV_KEY(EV_KEY::KEY_UP) => Some((EV_REL::REL_Y, -MOUSE_STEP_Y)),
70            EventCode::EV_KEY(EV_KEY::KEY_DOWN) => Some((EV_REL::REL_Y, MOUSE_STEP_Y)),
71            _ => None,
72        };
73
74        // Write mapped event
75        if let Some((e, n)) = e {
76            v.write_event(&InputEvent {
77                time: event.time,
78                event_code: EventCode::EV_REL(e),
79                value: n,
80            })?;
81
82            v.write_event(&InputEvent {
83                time: event.time,
84                event_code: EventCode::EV_SYN(EV_SYN::SYN_REPORT),
85                value: 0,
86            })?;
87        }
88    }
89}
Source

fn enable_property(&self, prop: &InputProp) -> Result<()>

Enables this property, a call to set_file will overwrite any previously set values

Note: Please use the enable function instead. This function is only available for the sake of maintaining compatibility with libevdev.

Source

fn enable_event_type(&self, ev_type: &EventType) -> Result<()>

Forcibly enable an event type on this device, even if the underlying device does not support it. While this cannot make the device actually report such events, it will now return true for libevdev_has_event_type().

This is a local modification only affecting only this representation of this device.

Note: Please use the enable function instead. This function is only available for the sake of maintaining compatibility with libevdev.

Source

fn enable_event_code( &self, ev_code: &EventCode, data: Option<EnableCodeData>, ) -> Result<()>

Forcibly enable an event type on this device, even if the underlying device does not support it. While this cannot make the device actually report such events, it will now return true for libevdev_has_event_code().

The last argument depends on the type and code: If type is EV_ABS, data must be a pointer to a struct input_absinfo containing the data for this axis. If type is EV_REP, data must be a pointer to a int containing the data for this axis. For all other types, the argument must be None.

Note: Please use the enable function instead. This function is only available for the sake of maintaining compatibility with libevdev.

Source

fn disable<E: Enable>(&self, d: E) -> Result<()>

Forcibly disable an EventType/EventCode on this device, even if the underlying device provides it. This effectively mutes the respective set of events. has() will return false for this EventType/EventCode

In most cases, a caller likely only wants to disable a single code, not the whole type.

Disabling EV_SYN will not work. In Peter’s Words “Don’t shoot yourself in the foot. It hurts”.

This is a local modification only affecting only this representation of this device.

Source

fn disable_event_type(&self, ev_type: &EventType) -> Result<()>

Forcibly disable an event type on this device, even if the underlying device provides it. This effectively mutes the respective set of events. libevdev will filter any events matching this type and none will reach the caller. libevdev_has_event_type() will return false for this type.

In most cases, a caller likely only wants to disable a single code, not the whole type. Use disable_event_code for that.

Disabling EV_SYN will not work. In Peter’s Words “Don’t shoot yourself in the foot. It hurts”.

This is a local modification only affecting only this representation of this device.

Note: Please use the disable function instead. This function is only available for the sake of maintaining compatibility with libevdev.

Source

fn disable_event_code(&self, code: &EventCode) -> Result<()>

Forcibly disable an event code on this device, even if the underlying device provides it. This effectively mutes the respective set of events. libevdev will filter any events matching this type and code and none will reach the caller. has_event_code will return false for this code.

Disabling all event codes for a given type will not disable the event type. Use disable_event_type for that.

This is a local modification only affecting only this representation of this device.

Disabling codes of type EV_SYN will not work. Don’t shoot yourself in the foot. It hurts.

Note: Please use the disable function instead. This function is only available for the sake of maintaining compatibility with libevdev.

Source

fn has<E: Enable>(&self, e: E) -> bool

Returns true if device support the InputProp/EventType/EventCode and false otherwise

Examples found in repository?
examples/evtest.rs (line 16)
13fn print_abs_bits(dev: &Device, axis: &EV_ABS) {
14    let code = EventCode::EV_ABS(axis.clone());
15
16    if !dev.has(code) {
17        return;
18    }
19
20    let abs = dev.abs_info(&code).unwrap();
21
22    println!("\tValue\t{}", abs.value);
23    println!("\tMin\t{}", abs.minimum);
24    println!("\tMax\t{}", abs.maximum);
25    if abs.fuzz != 0 {
26        println!("\tFuzz\t{}", abs.fuzz);
27    }
28    if abs.flat != 0 {
29        println!("\tFlat\t{}", abs.flat);
30    }
31    if abs.resolution != 0 {
32        println!("\tResolution\t{}", abs.resolution);
33    }
34}
35
36fn print_code_bits(dev: &Device, ev_type: &EventType) {
37    for code in EventCodeIterator::new(ev_type) {
38        if !dev.has(code) {
39            continue;
40        }
41
42        println!("    Event code: {}", code);
43        match code {
44            EventCode::EV_ABS(k) => print_abs_bits(dev, &k),
45            _ => (),
46        }
47    }
48}
49
50fn print_bits(dev: &Device) {
51    println!("Supported events:");
52
53    for ev_type in EventTypeIterator::new() {
54        if dev.has(ev_type) {
55            println!("  Event type: {} ", ev_type);
56        }
57
58        match ev_type {
59            EventType::EV_KEY
60            | EventType::EV_REL
61            | EventType::EV_ABS
62            | EventType::EV_LED => print_code_bits(dev, &ev_type),
63            _ => (),
64        }
65    }
66}
Source

fn has_property(&self, prop: &InputProp) -> bool

Returns true if device support the property and false otherwise

Note: Please use the has function instead. This function is only available for the sake of maintaining compatibility with libevdev.

Examples found in repository?
examples/evtest.rs (line 72)
68fn print_props(dev: &Device) {
69    println!("Properties:");
70
71    for input_prop in InputPropIterator::new() {
72        if dev.has_property(&input_prop) {
73            println!("  Property type: {}", input_prop);
74        }
75    }
76}
Source

fn has_event_type(&self, ev_type: &EventType) -> bool

Returns true is the device support this event type and false otherwise

Note: Please use the has function instead. This function is only available for the sake of maintaining compatibility with libevdev.

Source

fn has_event_code(&self, code: &EventCode) -> bool

Return true is the device support this event type and code and false otherwise

Note: Please use the has function instead. This function is only available for the sake of maintaining compatibility with libevdev.

Source

fn name(&self) -> Option<&str>

Get device’s name, as set by the kernel, or overridden by a call to set_name

Examples found in repository?
examples/evtest.rs (line 135)
104fn main() {
105    let mut args = std::env::args();
106
107    if args.len() != 2 {
108        usage();
109        std::process::exit(1);
110    }
111
112    let path = &args.nth(1).unwrap();
113    let mut file = OpenOptions::new()
114        .read(true)
115        .write(true)
116        .custom_flags(libc::O_NONBLOCK)
117        .open(path)
118        .unwrap();
119    let mut buffer = Vec::new();
120    let result = file.read_to_end(&mut buffer);
121    if result.is_ok() || result.unwrap_err().kind() != ErrorKind::WouldBlock {
122        println!("Failed to drain pending events from device file");
123    }
124
125    let u_d = UninitDevice::new().unwrap();
126    let d = u_d.set_file(file).unwrap();
127
128    println!(
129        "Input device ID: bus 0x{:x} vendor 0x{:x} product 0x{:x}",
130        d.bustype(),
131        d.vendor_id(),
132        d.product_id()
133    );
134    println!("Evdev version: {:x}", d.driver_version());
135    println!("Input device name: \"{}\"", d.name().unwrap_or(""));
136    println!("Phys location: {}", d.phys().unwrap_or(""));
137    println!("Uniq identifier: {}", d.uniq().unwrap_or(""));
138
139    print_bits(&d);
140    print_props(&d);
141
142    let mut a: io::Result<(ReadStatus, InputEvent)>;
143    loop {
144        a = d.next_event(ReadFlag::NORMAL);
145        if a.is_ok() {
146            let mut result = a.ok().unwrap();
147            match result.0 {
148                ReadStatus::Sync => {
149                    println!("::::::::::::::::::::: dropped ::::::::::::::::::::::");
150                    while result.0 == ReadStatus::Sync {
151                        print_sync_dropped_event(&result.1);
152                        a = d.next_event(ReadFlag::SYNC);
153                        if a.is_ok() {
154                            result = a.ok().unwrap();
155                        } else {
156                            break;
157                        }
158                    }
159                    println!("::::::::::::::::::::: re-synced ::::::::::::::::::::");
160                }
161                ReadStatus::Success => print_event(&result.1),
162            }
163        } else {
164            let err = a.err().unwrap();
165            match err.raw_os_error() {
166                Some(libc::EAGAIN) => continue,
167                _ => {
168                    println!("{}", err);
169                    break;
170                }
171            }
172        }
173    }
174}
More examples
Hide additional examples
examples/vmouse.rs (line 25)
9fn main() -> Result<(), std::io::Error> {
10    // Parse command line arguments
11    let mut args = std::env::args();
12
13    if args.len() != 2 {
14        let n = args.nth(0).unwrap();
15        println!("Usage: `{} DEVICE`, eg. `{} /dev/input/event13`", n, n);
16        std::process::exit(1);
17    }
18
19    let device = &args.nth(1).unwrap();
20
21    // Connect to real keyboard
22    let f = File::open(device)?;
23    let d = Device::new_from_file(f)?;
24
25    if let Some(n) = d.name() {
26        println!(
27            "Connected to device: '{}' ({:04x}:{:04x})",
28            n,
29            d.vendor_id(),
30            d.product_id()
31        );
32    }
33
34    // Create virtual device
35    let u = UninitDevice::new().unwrap();
36
37    // Setup device
38    // per: https://01.org/linuxgraphics/gfx-docs/drm/input/uinput.html#mouse-movements
39
40    u.set_name("Virtual Mouse");
41    u.set_bustype(BusType::BUS_USB as u16);
42    u.set_vendor_id(0xabcd);
43    u.set_product_id(0xefef);
44
45    // Note mouse keys have to be enabled for this to be detected
46    // as a usable device, see: https://stackoverflow.com/a/64559658/6074942
47    u.enable(EventCode::EV_KEY(EV_KEY::BTN_LEFT))?;
48    u.enable(EventCode::EV_KEY(EV_KEY::BTN_RIGHT))?;
49
50    u.enable(EventCode::EV_REL(EV_REL::REL_X))?;
51    u.enable(EventCode::EV_REL(EV_REL::REL_Y))?;
52
53    u.enable(EventCode::EV_SYN(EV_SYN::SYN_REPORT))?;
54
55    // Attempt to create UInputDevice from UninitDevice
56    let v = UInputDevice::create_from_device(&u)?;
57
58    loop {
59        // Fetch keyboard events
60        let (_status, event) = d.next_event(ReadFlag::NORMAL | ReadFlag::BLOCKING)?;
61
62        // Map these to mouse events
63        println!("Event: {:?}", event);
64
65        // Map direction keys to mouse events
66        let e = match event.event_code {
67            EventCode::EV_KEY(EV_KEY::KEY_RIGHT) => Some((EV_REL::REL_X, MOUSE_STEP_X)),
68            EventCode::EV_KEY(EV_KEY::KEY_LEFT) => Some((EV_REL::REL_X, -MOUSE_STEP_X)),
69            EventCode::EV_KEY(EV_KEY::KEY_UP) => Some((EV_REL::REL_Y, -MOUSE_STEP_Y)),
70            EventCode::EV_KEY(EV_KEY::KEY_DOWN) => Some((EV_REL::REL_Y, MOUSE_STEP_Y)),
71            _ => None,
72        };
73
74        // Write mapped event
75        if let Some((e, n)) = e {
76            v.write_event(&InputEvent {
77                time: event.time,
78                event_code: EventCode::EV_REL(e),
79                value: n,
80            })?;
81
82            v.write_event(&InputEvent {
83                time: event.time,
84                event_code: EventCode::EV_SYN(EV_SYN::SYN_REPORT),
85                value: 0,
86            })?;
87        }
88    }
89}
Source

fn phys(&self) -> Option<&str>

Get device’s physical location, as set by the kernel, or overridden by a call to set_phys

Examples found in repository?
examples/evtest.rs (line 136)
104fn main() {
105    let mut args = std::env::args();
106
107    if args.len() != 2 {
108        usage();
109        std::process::exit(1);
110    }
111
112    let path = &args.nth(1).unwrap();
113    let mut file = OpenOptions::new()
114        .read(true)
115        .write(true)
116        .custom_flags(libc::O_NONBLOCK)
117        .open(path)
118        .unwrap();
119    let mut buffer = Vec::new();
120    let result = file.read_to_end(&mut buffer);
121    if result.is_ok() || result.unwrap_err().kind() != ErrorKind::WouldBlock {
122        println!("Failed to drain pending events from device file");
123    }
124
125    let u_d = UninitDevice::new().unwrap();
126    let d = u_d.set_file(file).unwrap();
127
128    println!(
129        "Input device ID: bus 0x{:x} vendor 0x{:x} product 0x{:x}",
130        d.bustype(),
131        d.vendor_id(),
132        d.product_id()
133    );
134    println!("Evdev version: {:x}", d.driver_version());
135    println!("Input device name: \"{}\"", d.name().unwrap_or(""));
136    println!("Phys location: {}", d.phys().unwrap_or(""));
137    println!("Uniq identifier: {}", d.uniq().unwrap_or(""));
138
139    print_bits(&d);
140    print_props(&d);
141
142    let mut a: io::Result<(ReadStatus, InputEvent)>;
143    loop {
144        a = d.next_event(ReadFlag::NORMAL);
145        if a.is_ok() {
146            let mut result = a.ok().unwrap();
147            match result.0 {
148                ReadStatus::Sync => {
149                    println!("::::::::::::::::::::: dropped ::::::::::::::::::::::");
150                    while result.0 == ReadStatus::Sync {
151                        print_sync_dropped_event(&result.1);
152                        a = d.next_event(ReadFlag::SYNC);
153                        if a.is_ok() {
154                            result = a.ok().unwrap();
155                        } else {
156                            break;
157                        }
158                    }
159                    println!("::::::::::::::::::::: re-synced ::::::::::::::::::::");
160                }
161                ReadStatus::Success => print_event(&result.1),
162            }
163        } else {
164            let err = a.err().unwrap();
165            match err.raw_os_error() {
166                Some(libc::EAGAIN) => continue,
167                _ => {
168                    println!("{}", err);
169                    break;
170                }
171            }
172        }
173    }
174}
Source

fn uniq(&self) -> Option<&str>

Get device’s unique identifier, as set by the kernel, or overridden by a call to set_uniq

Examples found in repository?
examples/evtest.rs (line 137)
104fn main() {
105    let mut args = std::env::args();
106
107    if args.len() != 2 {
108        usage();
109        std::process::exit(1);
110    }
111
112    let path = &args.nth(1).unwrap();
113    let mut file = OpenOptions::new()
114        .read(true)
115        .write(true)
116        .custom_flags(libc::O_NONBLOCK)
117        .open(path)
118        .unwrap();
119    let mut buffer = Vec::new();
120    let result = file.read_to_end(&mut buffer);
121    if result.is_ok() || result.unwrap_err().kind() != ErrorKind::WouldBlock {
122        println!("Failed to drain pending events from device file");
123    }
124
125    let u_d = UninitDevice::new().unwrap();
126    let d = u_d.set_file(file).unwrap();
127
128    println!(
129        "Input device ID: bus 0x{:x} vendor 0x{:x} product 0x{:x}",
130        d.bustype(),
131        d.vendor_id(),
132        d.product_id()
133    );
134    println!("Evdev version: {:x}", d.driver_version());
135    println!("Input device name: \"{}\"", d.name().unwrap_or(""));
136    println!("Phys location: {}", d.phys().unwrap_or(""));
137    println!("Uniq identifier: {}", d.uniq().unwrap_or(""));
138
139    print_bits(&d);
140    print_props(&d);
141
142    let mut a: io::Result<(ReadStatus, InputEvent)>;
143    loop {
144        a = d.next_event(ReadFlag::NORMAL);
145        if a.is_ok() {
146            let mut result = a.ok().unwrap();
147            match result.0 {
148                ReadStatus::Sync => {
149                    println!("::::::::::::::::::::: dropped ::::::::::::::::::::::");
150                    while result.0 == ReadStatus::Sync {
151                        print_sync_dropped_event(&result.1);
152                        a = d.next_event(ReadFlag::SYNC);
153                        if a.is_ok() {
154                            result = a.ok().unwrap();
155                        } else {
156                            break;
157                        }
158                    }
159                    println!("::::::::::::::::::::: re-synced ::::::::::::::::::::");
160                }
161                ReadStatus::Success => print_event(&result.1),
162            }
163        } else {
164            let err = a.err().unwrap();
165            match err.raw_os_error() {
166                Some(libc::EAGAIN) => continue,
167                _ => {
168                    println!("{}", err);
169                    break;
170                }
171            }
172        }
173    }
174}
Source

fn set_name(&self, field: &str)

Examples found in repository?
examples/vmouse.rs (line 40)
9fn main() -> Result<(), std::io::Error> {
10    // Parse command line arguments
11    let mut args = std::env::args();
12
13    if args.len() != 2 {
14        let n = args.nth(0).unwrap();
15        println!("Usage: `{} DEVICE`, eg. `{} /dev/input/event13`", n, n);
16        std::process::exit(1);
17    }
18
19    let device = &args.nth(1).unwrap();
20
21    // Connect to real keyboard
22    let f = File::open(device)?;
23    let d = Device::new_from_file(f)?;
24
25    if let Some(n) = d.name() {
26        println!(
27            "Connected to device: '{}' ({:04x}:{:04x})",
28            n,
29            d.vendor_id(),
30            d.product_id()
31        );
32    }
33
34    // Create virtual device
35    let u = UninitDevice::new().unwrap();
36
37    // Setup device
38    // per: https://01.org/linuxgraphics/gfx-docs/drm/input/uinput.html#mouse-movements
39
40    u.set_name("Virtual Mouse");
41    u.set_bustype(BusType::BUS_USB as u16);
42    u.set_vendor_id(0xabcd);
43    u.set_product_id(0xefef);
44
45    // Note mouse keys have to be enabled for this to be detected
46    // as a usable device, see: https://stackoverflow.com/a/64559658/6074942
47    u.enable(EventCode::EV_KEY(EV_KEY::BTN_LEFT))?;
48    u.enable(EventCode::EV_KEY(EV_KEY::BTN_RIGHT))?;
49
50    u.enable(EventCode::EV_REL(EV_REL::REL_X))?;
51    u.enable(EventCode::EV_REL(EV_REL::REL_Y))?;
52
53    u.enable(EventCode::EV_SYN(EV_SYN::SYN_REPORT))?;
54
55    // Attempt to create UInputDevice from UninitDevice
56    let v = UInputDevice::create_from_device(&u)?;
57
58    loop {
59        // Fetch keyboard events
60        let (_status, event) = d.next_event(ReadFlag::NORMAL | ReadFlag::BLOCKING)?;
61
62        // Map these to mouse events
63        println!("Event: {:?}", event);
64
65        // Map direction keys to mouse events
66        let e = match event.event_code {
67            EventCode::EV_KEY(EV_KEY::KEY_RIGHT) => Some((EV_REL::REL_X, MOUSE_STEP_X)),
68            EventCode::EV_KEY(EV_KEY::KEY_LEFT) => Some((EV_REL::REL_X, -MOUSE_STEP_X)),
69            EventCode::EV_KEY(EV_KEY::KEY_UP) => Some((EV_REL::REL_Y, -MOUSE_STEP_Y)),
70            EventCode::EV_KEY(EV_KEY::KEY_DOWN) => Some((EV_REL::REL_Y, MOUSE_STEP_Y)),
71            _ => None,
72        };
73
74        // Write mapped event
75        if let Some((e, n)) = e {
76            v.write_event(&InputEvent {
77                time: event.time,
78                event_code: EventCode::EV_REL(e),
79                value: n,
80            })?;
81
82            v.write_event(&InputEvent {
83                time: event.time,
84                event_code: EventCode::EV_SYN(EV_SYN::SYN_REPORT),
85                value: 0,
86            })?;
87        }
88    }
89}
Source

fn set_phys(&self, field: &str)

Source

fn set_uniq(&self, field: &str)

Source

fn product_id(&self) -> u16

Examples found in repository?
examples/evtest.rs (line 132)
104fn main() {
105    let mut args = std::env::args();
106
107    if args.len() != 2 {
108        usage();
109        std::process::exit(1);
110    }
111
112    let path = &args.nth(1).unwrap();
113    let mut file = OpenOptions::new()
114        .read(true)
115        .write(true)
116        .custom_flags(libc::O_NONBLOCK)
117        .open(path)
118        .unwrap();
119    let mut buffer = Vec::new();
120    let result = file.read_to_end(&mut buffer);
121    if result.is_ok() || result.unwrap_err().kind() != ErrorKind::WouldBlock {
122        println!("Failed to drain pending events from device file");
123    }
124
125    let u_d = UninitDevice::new().unwrap();
126    let d = u_d.set_file(file).unwrap();
127
128    println!(
129        "Input device ID: bus 0x{:x} vendor 0x{:x} product 0x{:x}",
130        d.bustype(),
131        d.vendor_id(),
132        d.product_id()
133    );
134    println!("Evdev version: {:x}", d.driver_version());
135    println!("Input device name: \"{}\"", d.name().unwrap_or(""));
136    println!("Phys location: {}", d.phys().unwrap_or(""));
137    println!("Uniq identifier: {}", d.uniq().unwrap_or(""));
138
139    print_bits(&d);
140    print_props(&d);
141
142    let mut a: io::Result<(ReadStatus, InputEvent)>;
143    loop {
144        a = d.next_event(ReadFlag::NORMAL);
145        if a.is_ok() {
146            let mut result = a.ok().unwrap();
147            match result.0 {
148                ReadStatus::Sync => {
149                    println!("::::::::::::::::::::: dropped ::::::::::::::::::::::");
150                    while result.0 == ReadStatus::Sync {
151                        print_sync_dropped_event(&result.1);
152                        a = d.next_event(ReadFlag::SYNC);
153                        if a.is_ok() {
154                            result = a.ok().unwrap();
155                        } else {
156                            break;
157                        }
158                    }
159                    println!("::::::::::::::::::::: re-synced ::::::::::::::::::::");
160                }
161                ReadStatus::Success => print_event(&result.1),
162            }
163        } else {
164            let err = a.err().unwrap();
165            match err.raw_os_error() {
166                Some(libc::EAGAIN) => continue,
167                _ => {
168                    println!("{}", err);
169                    break;
170                }
171            }
172        }
173    }
174}
More examples
Hide additional examples
examples/vmouse.rs (line 30)
9fn main() -> Result<(), std::io::Error> {
10    // Parse command line arguments
11    let mut args = std::env::args();
12
13    if args.len() != 2 {
14        let n = args.nth(0).unwrap();
15        println!("Usage: `{} DEVICE`, eg. `{} /dev/input/event13`", n, n);
16        std::process::exit(1);
17    }
18
19    let device = &args.nth(1).unwrap();
20
21    // Connect to real keyboard
22    let f = File::open(device)?;
23    let d = Device::new_from_file(f)?;
24
25    if let Some(n) = d.name() {
26        println!(
27            "Connected to device: '{}' ({:04x}:{:04x})",
28            n,
29            d.vendor_id(),
30            d.product_id()
31        );
32    }
33
34    // Create virtual device
35    let u = UninitDevice::new().unwrap();
36
37    // Setup device
38    // per: https://01.org/linuxgraphics/gfx-docs/drm/input/uinput.html#mouse-movements
39
40    u.set_name("Virtual Mouse");
41    u.set_bustype(BusType::BUS_USB as u16);
42    u.set_vendor_id(0xabcd);
43    u.set_product_id(0xefef);
44
45    // Note mouse keys have to be enabled for this to be detected
46    // as a usable device, see: https://stackoverflow.com/a/64559658/6074942
47    u.enable(EventCode::EV_KEY(EV_KEY::BTN_LEFT))?;
48    u.enable(EventCode::EV_KEY(EV_KEY::BTN_RIGHT))?;
49
50    u.enable(EventCode::EV_REL(EV_REL::REL_X))?;
51    u.enable(EventCode::EV_REL(EV_REL::REL_Y))?;
52
53    u.enable(EventCode::EV_SYN(EV_SYN::SYN_REPORT))?;
54
55    // Attempt to create UInputDevice from UninitDevice
56    let v = UInputDevice::create_from_device(&u)?;
57
58    loop {
59        // Fetch keyboard events
60        let (_status, event) = d.next_event(ReadFlag::NORMAL | ReadFlag::BLOCKING)?;
61
62        // Map these to mouse events
63        println!("Event: {:?}", event);
64
65        // Map direction keys to mouse events
66        let e = match event.event_code {
67            EventCode::EV_KEY(EV_KEY::KEY_RIGHT) => Some((EV_REL::REL_X, MOUSE_STEP_X)),
68            EventCode::EV_KEY(EV_KEY::KEY_LEFT) => Some((EV_REL::REL_X, -MOUSE_STEP_X)),
69            EventCode::EV_KEY(EV_KEY::KEY_UP) => Some((EV_REL::REL_Y, -MOUSE_STEP_Y)),
70            EventCode::EV_KEY(EV_KEY::KEY_DOWN) => Some((EV_REL::REL_Y, MOUSE_STEP_Y)),
71            _ => None,
72        };
73
74        // Write mapped event
75        if let Some((e, n)) = e {
76            v.write_event(&InputEvent {
77                time: event.time,
78                event_code: EventCode::EV_REL(e),
79                value: n,
80            })?;
81
82            v.write_event(&InputEvent {
83                time: event.time,
84                event_code: EventCode::EV_SYN(EV_SYN::SYN_REPORT),
85                value: 0,
86            })?;
87        }
88    }
89}
Source

fn vendor_id(&self) -> u16

Examples found in repository?
examples/evtest.rs (line 131)
104fn main() {
105    let mut args = std::env::args();
106
107    if args.len() != 2 {
108        usage();
109        std::process::exit(1);
110    }
111
112    let path = &args.nth(1).unwrap();
113    let mut file = OpenOptions::new()
114        .read(true)
115        .write(true)
116        .custom_flags(libc::O_NONBLOCK)
117        .open(path)
118        .unwrap();
119    let mut buffer = Vec::new();
120    let result = file.read_to_end(&mut buffer);
121    if result.is_ok() || result.unwrap_err().kind() != ErrorKind::WouldBlock {
122        println!("Failed to drain pending events from device file");
123    }
124
125    let u_d = UninitDevice::new().unwrap();
126    let d = u_d.set_file(file).unwrap();
127
128    println!(
129        "Input device ID: bus 0x{:x} vendor 0x{:x} product 0x{:x}",
130        d.bustype(),
131        d.vendor_id(),
132        d.product_id()
133    );
134    println!("Evdev version: {:x}", d.driver_version());
135    println!("Input device name: \"{}\"", d.name().unwrap_or(""));
136    println!("Phys location: {}", d.phys().unwrap_or(""));
137    println!("Uniq identifier: {}", d.uniq().unwrap_or(""));
138
139    print_bits(&d);
140    print_props(&d);
141
142    let mut a: io::Result<(ReadStatus, InputEvent)>;
143    loop {
144        a = d.next_event(ReadFlag::NORMAL);
145        if a.is_ok() {
146            let mut result = a.ok().unwrap();
147            match result.0 {
148                ReadStatus::Sync => {
149                    println!("::::::::::::::::::::: dropped ::::::::::::::::::::::");
150                    while result.0 == ReadStatus::Sync {
151                        print_sync_dropped_event(&result.1);
152                        a = d.next_event(ReadFlag::SYNC);
153                        if a.is_ok() {
154                            result = a.ok().unwrap();
155                        } else {
156                            break;
157                        }
158                    }
159                    println!("::::::::::::::::::::: re-synced ::::::::::::::::::::");
160                }
161                ReadStatus::Success => print_event(&result.1),
162            }
163        } else {
164            let err = a.err().unwrap();
165            match err.raw_os_error() {
166                Some(libc::EAGAIN) => continue,
167                _ => {
168                    println!("{}", err);
169                    break;
170                }
171            }
172        }
173    }
174}
More examples
Hide additional examples
examples/vmouse.rs (line 29)
9fn main() -> Result<(), std::io::Error> {
10    // Parse command line arguments
11    let mut args = std::env::args();
12
13    if args.len() != 2 {
14        let n = args.nth(0).unwrap();
15        println!("Usage: `{} DEVICE`, eg. `{} /dev/input/event13`", n, n);
16        std::process::exit(1);
17    }
18
19    let device = &args.nth(1).unwrap();
20
21    // Connect to real keyboard
22    let f = File::open(device)?;
23    let d = Device::new_from_file(f)?;
24
25    if let Some(n) = d.name() {
26        println!(
27            "Connected to device: '{}' ({:04x}:{:04x})",
28            n,
29            d.vendor_id(),
30            d.product_id()
31        );
32    }
33
34    // Create virtual device
35    let u = UninitDevice::new().unwrap();
36
37    // Setup device
38    // per: https://01.org/linuxgraphics/gfx-docs/drm/input/uinput.html#mouse-movements
39
40    u.set_name("Virtual Mouse");
41    u.set_bustype(BusType::BUS_USB as u16);
42    u.set_vendor_id(0xabcd);
43    u.set_product_id(0xefef);
44
45    // Note mouse keys have to be enabled for this to be detected
46    // as a usable device, see: https://stackoverflow.com/a/64559658/6074942
47    u.enable(EventCode::EV_KEY(EV_KEY::BTN_LEFT))?;
48    u.enable(EventCode::EV_KEY(EV_KEY::BTN_RIGHT))?;
49
50    u.enable(EventCode::EV_REL(EV_REL::REL_X))?;
51    u.enable(EventCode::EV_REL(EV_REL::REL_Y))?;
52
53    u.enable(EventCode::EV_SYN(EV_SYN::SYN_REPORT))?;
54
55    // Attempt to create UInputDevice from UninitDevice
56    let v = UInputDevice::create_from_device(&u)?;
57
58    loop {
59        // Fetch keyboard events
60        let (_status, event) = d.next_event(ReadFlag::NORMAL | ReadFlag::BLOCKING)?;
61
62        // Map these to mouse events
63        println!("Event: {:?}", event);
64
65        // Map direction keys to mouse events
66        let e = match event.event_code {
67            EventCode::EV_KEY(EV_KEY::KEY_RIGHT) => Some((EV_REL::REL_X, MOUSE_STEP_X)),
68            EventCode::EV_KEY(EV_KEY::KEY_LEFT) => Some((EV_REL::REL_X, -MOUSE_STEP_X)),
69            EventCode::EV_KEY(EV_KEY::KEY_UP) => Some((EV_REL::REL_Y, -MOUSE_STEP_Y)),
70            EventCode::EV_KEY(EV_KEY::KEY_DOWN) => Some((EV_REL::REL_Y, MOUSE_STEP_Y)),
71            _ => None,
72        };
73
74        // Write mapped event
75        if let Some((e, n)) = e {
76            v.write_event(&InputEvent {
77                time: event.time,
78                event_code: EventCode::EV_REL(e),
79                value: n,
80            })?;
81
82            v.write_event(&InputEvent {
83                time: event.time,
84                event_code: EventCode::EV_SYN(EV_SYN::SYN_REPORT),
85                value: 0,
86            })?;
87        }
88    }
89}
Source

fn bustype(&self) -> u16

Examples found in repository?
examples/evtest.rs (line 130)
104fn main() {
105    let mut args = std::env::args();
106
107    if args.len() != 2 {
108        usage();
109        std::process::exit(1);
110    }
111
112    let path = &args.nth(1).unwrap();
113    let mut file = OpenOptions::new()
114        .read(true)
115        .write(true)
116        .custom_flags(libc::O_NONBLOCK)
117        .open(path)
118        .unwrap();
119    let mut buffer = Vec::new();
120    let result = file.read_to_end(&mut buffer);
121    if result.is_ok() || result.unwrap_err().kind() != ErrorKind::WouldBlock {
122        println!("Failed to drain pending events from device file");
123    }
124
125    let u_d = UninitDevice::new().unwrap();
126    let d = u_d.set_file(file).unwrap();
127
128    println!(
129        "Input device ID: bus 0x{:x} vendor 0x{:x} product 0x{:x}",
130        d.bustype(),
131        d.vendor_id(),
132        d.product_id()
133    );
134    println!("Evdev version: {:x}", d.driver_version());
135    println!("Input device name: \"{}\"", d.name().unwrap_or(""));
136    println!("Phys location: {}", d.phys().unwrap_or(""));
137    println!("Uniq identifier: {}", d.uniq().unwrap_or(""));
138
139    print_bits(&d);
140    print_props(&d);
141
142    let mut a: io::Result<(ReadStatus, InputEvent)>;
143    loop {
144        a = d.next_event(ReadFlag::NORMAL);
145        if a.is_ok() {
146            let mut result = a.ok().unwrap();
147            match result.0 {
148                ReadStatus::Sync => {
149                    println!("::::::::::::::::::::: dropped ::::::::::::::::::::::");
150                    while result.0 == ReadStatus::Sync {
151                        print_sync_dropped_event(&result.1);
152                        a = d.next_event(ReadFlag::SYNC);
153                        if a.is_ok() {
154                            result = a.ok().unwrap();
155                        } else {
156                            break;
157                        }
158                    }
159                    println!("::::::::::::::::::::: re-synced ::::::::::::::::::::");
160                }
161                ReadStatus::Success => print_event(&result.1),
162            }
163        } else {
164            let err = a.err().unwrap();
165            match err.raw_os_error() {
166                Some(libc::EAGAIN) => continue,
167                _ => {
168                    println!("{}", err);
169                    break;
170                }
171            }
172        }
173    }
174}
Source

fn version(&self) -> u16

Source

fn set_product_id(&self, field: u16)

Examples found in repository?
examples/vmouse.rs (line 43)
9fn main() -> Result<(), std::io::Error> {
10    // Parse command line arguments
11    let mut args = std::env::args();
12
13    if args.len() != 2 {
14        let n = args.nth(0).unwrap();
15        println!("Usage: `{} DEVICE`, eg. `{} /dev/input/event13`", n, n);
16        std::process::exit(1);
17    }
18
19    let device = &args.nth(1).unwrap();
20
21    // Connect to real keyboard
22    let f = File::open(device)?;
23    let d = Device::new_from_file(f)?;
24
25    if let Some(n) = d.name() {
26        println!(
27            "Connected to device: '{}' ({:04x}:{:04x})",
28            n,
29            d.vendor_id(),
30            d.product_id()
31        );
32    }
33
34    // Create virtual device
35    let u = UninitDevice::new().unwrap();
36
37    // Setup device
38    // per: https://01.org/linuxgraphics/gfx-docs/drm/input/uinput.html#mouse-movements
39
40    u.set_name("Virtual Mouse");
41    u.set_bustype(BusType::BUS_USB as u16);
42    u.set_vendor_id(0xabcd);
43    u.set_product_id(0xefef);
44
45    // Note mouse keys have to be enabled for this to be detected
46    // as a usable device, see: https://stackoverflow.com/a/64559658/6074942
47    u.enable(EventCode::EV_KEY(EV_KEY::BTN_LEFT))?;
48    u.enable(EventCode::EV_KEY(EV_KEY::BTN_RIGHT))?;
49
50    u.enable(EventCode::EV_REL(EV_REL::REL_X))?;
51    u.enable(EventCode::EV_REL(EV_REL::REL_Y))?;
52
53    u.enable(EventCode::EV_SYN(EV_SYN::SYN_REPORT))?;
54
55    // Attempt to create UInputDevice from UninitDevice
56    let v = UInputDevice::create_from_device(&u)?;
57
58    loop {
59        // Fetch keyboard events
60        let (_status, event) = d.next_event(ReadFlag::NORMAL | ReadFlag::BLOCKING)?;
61
62        // Map these to mouse events
63        println!("Event: {:?}", event);
64
65        // Map direction keys to mouse events
66        let e = match event.event_code {
67            EventCode::EV_KEY(EV_KEY::KEY_RIGHT) => Some((EV_REL::REL_X, MOUSE_STEP_X)),
68            EventCode::EV_KEY(EV_KEY::KEY_LEFT) => Some((EV_REL::REL_X, -MOUSE_STEP_X)),
69            EventCode::EV_KEY(EV_KEY::KEY_UP) => Some((EV_REL::REL_Y, -MOUSE_STEP_Y)),
70            EventCode::EV_KEY(EV_KEY::KEY_DOWN) => Some((EV_REL::REL_Y, MOUSE_STEP_Y)),
71            _ => None,
72        };
73
74        // Write mapped event
75        if let Some((e, n)) = e {
76            v.write_event(&InputEvent {
77                time: event.time,
78                event_code: EventCode::EV_REL(e),
79                value: n,
80            })?;
81
82            v.write_event(&InputEvent {
83                time: event.time,
84                event_code: EventCode::EV_SYN(EV_SYN::SYN_REPORT),
85                value: 0,
86            })?;
87        }
88    }
89}
Source

fn set_vendor_id(&self, field: u16)

Examples found in repository?
examples/vmouse.rs (line 42)
9fn main() -> Result<(), std::io::Error> {
10    // Parse command line arguments
11    let mut args = std::env::args();
12
13    if args.len() != 2 {
14        let n = args.nth(0).unwrap();
15        println!("Usage: `{} DEVICE`, eg. `{} /dev/input/event13`", n, n);
16        std::process::exit(1);
17    }
18
19    let device = &args.nth(1).unwrap();
20
21    // Connect to real keyboard
22    let f = File::open(device)?;
23    let d = Device::new_from_file(f)?;
24
25    if let Some(n) = d.name() {
26        println!(
27            "Connected to device: '{}' ({:04x}:{:04x})",
28            n,
29            d.vendor_id(),
30            d.product_id()
31        );
32    }
33
34    // Create virtual device
35    let u = UninitDevice::new().unwrap();
36
37    // Setup device
38    // per: https://01.org/linuxgraphics/gfx-docs/drm/input/uinput.html#mouse-movements
39
40    u.set_name("Virtual Mouse");
41    u.set_bustype(BusType::BUS_USB as u16);
42    u.set_vendor_id(0xabcd);
43    u.set_product_id(0xefef);
44
45    // Note mouse keys have to be enabled for this to be detected
46    // as a usable device, see: https://stackoverflow.com/a/64559658/6074942
47    u.enable(EventCode::EV_KEY(EV_KEY::BTN_LEFT))?;
48    u.enable(EventCode::EV_KEY(EV_KEY::BTN_RIGHT))?;
49
50    u.enable(EventCode::EV_REL(EV_REL::REL_X))?;
51    u.enable(EventCode::EV_REL(EV_REL::REL_Y))?;
52
53    u.enable(EventCode::EV_SYN(EV_SYN::SYN_REPORT))?;
54
55    // Attempt to create UInputDevice from UninitDevice
56    let v = UInputDevice::create_from_device(&u)?;
57
58    loop {
59        // Fetch keyboard events
60        let (_status, event) = d.next_event(ReadFlag::NORMAL | ReadFlag::BLOCKING)?;
61
62        // Map these to mouse events
63        println!("Event: {:?}", event);
64
65        // Map direction keys to mouse events
66        let e = match event.event_code {
67            EventCode::EV_KEY(EV_KEY::KEY_RIGHT) => Some((EV_REL::REL_X, MOUSE_STEP_X)),
68            EventCode::EV_KEY(EV_KEY::KEY_LEFT) => Some((EV_REL::REL_X, -MOUSE_STEP_X)),
69            EventCode::EV_KEY(EV_KEY::KEY_UP) => Some((EV_REL::REL_Y, -MOUSE_STEP_Y)),
70            EventCode::EV_KEY(EV_KEY::KEY_DOWN) => Some((EV_REL::REL_Y, MOUSE_STEP_Y)),
71            _ => None,
72        };
73
74        // Write mapped event
75        if let Some((e, n)) = e {
76            v.write_event(&InputEvent {
77                time: event.time,
78                event_code: EventCode::EV_REL(e),
79                value: n,
80            })?;
81
82            v.write_event(&InputEvent {
83                time: event.time,
84                event_code: EventCode::EV_SYN(EV_SYN::SYN_REPORT),
85                value: 0,
86            })?;
87        }
88    }
89}
Source

fn set_bustype(&self, field: u16)

Examples found in repository?
examples/vmouse.rs (line 41)
9fn main() -> Result<(), std::io::Error> {
10    // Parse command line arguments
11    let mut args = std::env::args();
12
13    if args.len() != 2 {
14        let n = args.nth(0).unwrap();
15        println!("Usage: `{} DEVICE`, eg. `{} /dev/input/event13`", n, n);
16        std::process::exit(1);
17    }
18
19    let device = &args.nth(1).unwrap();
20
21    // Connect to real keyboard
22    let f = File::open(device)?;
23    let d = Device::new_from_file(f)?;
24
25    if let Some(n) = d.name() {
26        println!(
27            "Connected to device: '{}' ({:04x}:{:04x})",
28            n,
29            d.vendor_id(),
30            d.product_id()
31        );
32    }
33
34    // Create virtual device
35    let u = UninitDevice::new().unwrap();
36
37    // Setup device
38    // per: https://01.org/linuxgraphics/gfx-docs/drm/input/uinput.html#mouse-movements
39
40    u.set_name("Virtual Mouse");
41    u.set_bustype(BusType::BUS_USB as u16);
42    u.set_vendor_id(0xabcd);
43    u.set_product_id(0xefef);
44
45    // Note mouse keys have to be enabled for this to be detected
46    // as a usable device, see: https://stackoverflow.com/a/64559658/6074942
47    u.enable(EventCode::EV_KEY(EV_KEY::BTN_LEFT))?;
48    u.enable(EventCode::EV_KEY(EV_KEY::BTN_RIGHT))?;
49
50    u.enable(EventCode::EV_REL(EV_REL::REL_X))?;
51    u.enable(EventCode::EV_REL(EV_REL::REL_Y))?;
52
53    u.enable(EventCode::EV_SYN(EV_SYN::SYN_REPORT))?;
54
55    // Attempt to create UInputDevice from UninitDevice
56    let v = UInputDevice::create_from_device(&u)?;
57
58    loop {
59        // Fetch keyboard events
60        let (_status, event) = d.next_event(ReadFlag::NORMAL | ReadFlag::BLOCKING)?;
61
62        // Map these to mouse events
63        println!("Event: {:?}", event);
64
65        // Map direction keys to mouse events
66        let e = match event.event_code {
67            EventCode::EV_KEY(EV_KEY::KEY_RIGHT) => Some((EV_REL::REL_X, MOUSE_STEP_X)),
68            EventCode::EV_KEY(EV_KEY::KEY_LEFT) => Some((EV_REL::REL_X, -MOUSE_STEP_X)),
69            EventCode::EV_KEY(EV_KEY::KEY_UP) => Some((EV_REL::REL_Y, -MOUSE_STEP_Y)),
70            EventCode::EV_KEY(EV_KEY::KEY_DOWN) => Some((EV_REL::REL_Y, MOUSE_STEP_Y)),
71            _ => None,
72        };
73
74        // Write mapped event
75        if let Some((e, n)) = e {
76            v.write_event(&InputEvent {
77                time: event.time,
78                event_code: EventCode::EV_REL(e),
79                value: n,
80            })?;
81
82            v.write_event(&InputEvent {
83                time: event.time,
84                event_code: EventCode::EV_SYN(EV_SYN::SYN_REPORT),
85                value: 0,
86            })?;
87        }
88    }
89}
Source

fn set_version(&self, field: u16)

Source

fn abs_info(&self, code: &EventCode) -> Option<AbsInfo>

Get the axis info for the given axis, as advertised by the kernel.

Returns the AbsInfo for the given the code or None if the device doesn’t support this code

Examples found in repository?
examples/evtest.rs (line 20)
13fn print_abs_bits(dev: &Device, axis: &EV_ABS) {
14    let code = EventCode::EV_ABS(axis.clone());
15
16    if !dev.has(code) {
17        return;
18    }
19
20    let abs = dev.abs_info(&code).unwrap();
21
22    println!("\tValue\t{}", abs.value);
23    println!("\tMin\t{}", abs.minimum);
24    println!("\tMax\t{}", abs.maximum);
25    if abs.fuzz != 0 {
26        println!("\tFuzz\t{}", abs.fuzz);
27    }
28    if abs.flat != 0 {
29        println!("\tFlat\t{}", abs.flat);
30    }
31    if abs.resolution != 0 {
32        println!("\tResolution\t{}", abs.resolution);
33    }
34}
Source

fn set_abs_info(&self, code: &EventCode, absinfo: &AbsInfo)

Change the abs info for the given EV_ABS event code, if the code exists.

This function has no effect if has_event_code returns false for this code.

Source

fn event_value(&self, code: &EventCode) -> Option<i32>

Returns the current value of the event type.

If the device supports this event type and code, the return value is set to the current value of this axis. Otherwise, None is returned.

Source

fn set_event_value(&self, code: &EventCode, val: i32) -> Result<()>

Set the value for a given event type and code.

This only makes sense for some event types, e.g. setting the value for EV_REL is pointless.

This is a local modification only affecting only this representation of this device. A future call to event_value() will return this value, unless the value was overwritten by an event.

If the device supports ABS_MT_SLOT, the value set for any ABS_MT_* event code is the value of the currently active slot. You should use set_slot_value instead.

If the device supports ABS_MT_SLOT and the type is EV_ABS and the code is ABS_MT_SLOT, the value must be a positive number less then the number of slots on the device. Otherwise, set_event_value returns Err.

Source

fn abs_minimum(&self, code: u32) -> Result<i32>

Source

fn abs_maximum(&self, code: u32) -> Result<i32>

Source

fn abs_fuzz(&self, code: u32) -> Result<i32>

Source

fn abs_flat(&self, code: u32) -> Result<i32>

Source

fn abs_resolution(&self, code: u32) -> Result<i32>

Source

fn set_abs_minimum(&self, code: u32, val: i32)

Source

fn set_abs_maximum(&self, code: u32, val: i32)

Source

fn set_abs_fuzz(&self, code: u32, val: i32)

Source

fn set_abs_flat(&self, code: u32, val: i32)

Source

fn set_abs_resolution(&self, code: u32, val: i32)

Source

fn slot_value(&self, slot: u32, code: &EventCode) -> Option<i32>

Return the current value of the code for the given slot.

If the device supports this event code, the return value is is set to the current value of this axis. Otherwise, or if the event code is not an ABS_MT_* event code, None is returned

Source

fn set_slot_value(&self, slot: u32, code: &EventCode, val: i32) -> Result<()>

Set the value for a given code for the given slot.

This is a local modification only affecting only this representation of this device. A future call to slot_value will return this value, unless the value was overwritten by an event.

This function does not set event values for axes outside the ABS_MT range, use set_event_value instead.

Source

fn num_slots(&self) -> Option<i32>

Get the number of slots supported by this device.

The number of slots supported, or None if the device does not provide any slots

A device may provide ABS_MT_SLOT but a total number of 0 slots. Hence the return value of None for “device does not provide slots at all”

Source

fn current_slot(&self) -> Option<i32>

Get the currently active slot.

This may differ from the value an ioctl may return at this time as events may have been read off the file since changing the slot value but those events are still in the buffer waiting to be processed. The returned value is the value a caller would see if it were to process events manually one-by-one.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§