device: add general event sender

This commit is contained in:
meh 2016-05-07 16:38:59 +02:00
parent cc112415c5
commit 35d74308e1
1 changed files with 7 additions and 0 deletions

View File

@ -4,6 +4,7 @@ use libc::{timeval, gettimeofday};
use nix::unistd;
use ffi::*;
use {Result as Res, event};
use event::{Kind, Code};
/// The virtual device.
pub struct Device {
@ -44,6 +45,12 @@ impl Device {
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.
pub fn press<T: event::Press>(&mut self, event: &T) -> Res<()> {
self.write(event.kind(), event.code(), 1)