device: add general event sender
This commit is contained in:
parent
cc112415c5
commit
35d74308e1
@ -4,6 +4,7 @@ use libc::{timeval, gettimeofday};
|
|||||||
use nix::unistd;
|
use nix::unistd;
|
||||||
use ffi::*;
|
use ffi::*;
|
||||||
use {Result as Res, event};
|
use {Result as Res, event};
|
||||||
|
use event::{Kind, Code};
|
||||||
|
|
||||||
/// The virtual device.
|
/// The virtual device.
|
||||||
pub struct Device {
|
pub struct Device {
|
||||||
@ -44,6 +45,12 @@ impl Device {
|
|||||||
self.write(EV_SYN, SYN_REPORT, 0)
|
self.write(EV_SYN, SYN_REPORT, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Send an event.
|
||||||
|
pub fn send<T: Into<event::Event>>(&mut self, event: T, value: i32) -> Res<()> {
|
||||||
|
let event = event.into();
|
||||||
|
self.write(event.kind(), event.code(), value)
|
||||||
|
}
|
||||||
|
|
||||||
/// Send a press event.
|
/// Send a press event.
|
||||||
pub fn press<T: event::Press>(&mut self, event: &T) -> Res<()> {
|
pub fn press<T: event::Press>(&mut self, event: &T) -> Res<()> {
|
||||||
self.write(event.kind(), event.code(), 1)
|
self.write(event.kind(), event.code(), 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user