bad try
This commit is contained in:
parent
35d74308e1
commit
7dd042f34e
@ -14,9 +14,6 @@ libc = "0.2"
|
|||||||
nix = "0.5"
|
nix = "0.5"
|
||||||
uinput-sys = "0.1"
|
uinput-sys = "0.1"
|
||||||
|
|
||||||
custom_derive = "0.1"
|
|
||||||
enum_derive = "0.1"
|
|
||||||
|
|
||||||
[dependencies.libudev]
|
[dependencies.libudev]
|
||||||
optional = true
|
optional = true
|
||||||
version = "0.2"
|
version = "0.2"
|
||||||
|
@ -5,8 +5,7 @@ use libc::c_int;
|
|||||||
use nix::{self, fcntl, unistd, Errno};
|
use nix::{self, fcntl, unistd, Errno};
|
||||||
use nix::sys::stat;
|
use nix::sys::stat;
|
||||||
use ffi::*;
|
use ffi::*;
|
||||||
use {Result as Res, Error, Device, Event};
|
use {Result as Res, Error, Device};
|
||||||
use event::{self, Kind, Code};
|
|
||||||
|
|
||||||
#[cfg(feature = "udev")]
|
#[cfg(feature = "udev")]
|
||||||
use udev;
|
use udev;
|
||||||
@ -88,6 +87,18 @@ impl Builder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn event(mut self) -> Res<Self> {
|
||||||
|
self.abs = None;
|
||||||
|
unsafe {
|
||||||
|
//try!(Errno::result(ui_set_evbit(self.fd, EV_KEY)));
|
||||||
|
//try!(Errno::result(ui_set_keybit(self.fd, KEY_H)));
|
||||||
|
ui_set_evbit(self.fd, &EV_KEY as *const c_int)?;
|
||||||
|
ui_set_keybit(self.fd, &KEY_H as *const c_int)?;
|
||||||
|
//try!(ui_set_keybit(self.fd, &KEY_H));
|
||||||
|
}
|
||||||
|
Ok(self)
|
||||||
|
}
|
||||||
|
/*
|
||||||
/// Enable the given event.
|
/// Enable the given event.
|
||||||
pub fn event<T: Into<Event>>(mut self, value: T) -> Res<Self> {
|
pub fn event<T: Into<Event>>(mut self, value: T) -> Res<Self> {
|
||||||
self.abs = None;
|
self.abs = None;
|
||||||
@ -229,7 +240,7 @@ impl Builder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
/// Set the maximum value for the previously enabled absolute event.
|
/// Set the maximum value for the previously enabled absolute event.
|
||||||
pub fn max(mut self, value: i32) -> Self {
|
pub fn max(mut self, value: i32) -> Self {
|
||||||
self.def.absmax[self.abs.unwrap() as usize] = value;
|
self.def.absmax[self.abs.unwrap() as usize] = value;
|
||||||
@ -261,7 +272,9 @@ impl Builder {
|
|||||||
let size = mem::size_of_val(&self.def);
|
let size = mem::size_of_val(&self.def);
|
||||||
|
|
||||||
try!(unistd::write(self.fd, slice::from_raw_parts(ptr, size)));
|
try!(unistd::write(self.fd, slice::from_raw_parts(ptr, size)));
|
||||||
try!(Errno::result(ui_dev_create(self.fd)));
|
//todo: try!(Errno::result(ui_dev_create(self.fd)));
|
||||||
|
// try1: Errno::result(ui_dev_create(self.fd)).unwrap();
|
||||||
|
try!(ui_dev_create(self.fd));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Device::new(self.fd))
|
Ok(Device::new(self.fd))
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
use std::{mem, ptr, slice};
|
use std::{mem, ptr, slice};
|
||||||
use libc::c_int;
|
use libc::c_int;
|
||||||
use libc::{timeval, gettimeofday};
|
use libc::{timeval, gettimeofday, input_event};
|
||||||
use nix::unistd;
|
use nix::unistd;
|
||||||
use ffi::*;
|
use ffi::*;
|
||||||
use {Result as Res, event};
|
use {Result as Res};
|
||||||
use event::{Kind, Code};
|
|
||||||
|
|
||||||
/// The virtual device.
|
/// The virtual device.
|
||||||
pub struct Device {
|
pub struct Device {
|
||||||
@ -24,7 +23,7 @@ impl Device {
|
|||||||
unsafe {
|
unsafe {
|
||||||
let mut event = input_event {
|
let mut event = input_event {
|
||||||
time: timeval { tv_sec: 0, tv_usec: 0 },
|
time: timeval { tv_sec: 0, tv_usec: 0 },
|
||||||
kind: kind as u16,
|
type_: kind as u16,
|
||||||
code: code as u16,
|
code: code as u16,
|
||||||
value: value as i32,
|
value: value as i32,
|
||||||
};
|
};
|
||||||
@ -46,39 +45,38 @@ impl Device {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Send an event.
|
/// Send an event.
|
||||||
pub fn send<T: Into<event::Event>>(&mut self, event: T, value: i32) -> Res<()> {
|
pub fn send(&mut self, kind: c_int, code: c_int, value: i32) -> Res<()> {
|
||||||
let event = event.into();
|
self.write(kind, code, value)
|
||||||
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(&mut self, kind: c_int, code: c_int) -> Res<()> {
|
||||||
self.write(event.kind(), event.code(), 1)
|
self.write(kind, code, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a release event.
|
/// Send a release event.
|
||||||
pub fn release<T: event::Release>(&mut self, event: &T) -> Res<()> {
|
pub fn release(&mut self, kind: c_int, code: c_int) -> Res<()> {
|
||||||
self.write(event.kind(), event.code(), 0)
|
self.write(kind, code, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a press and release event.
|
/// Send a press and release event.
|
||||||
pub fn click<T: event::Press + event::Release>(&mut self, event: &T) -> Res<()> {
|
pub fn click(&mut self, kind: c_int, code: c_int) -> Res<()> {
|
||||||
try!(self.press(event));
|
try!(self.press(kind, code));
|
||||||
try!(self.release(event));
|
try!(self.release(kind, code));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a relative or absolute positioning event.
|
/// Send a relative or absolute positioning event.
|
||||||
pub fn position<T: event::Position>(&mut self, event: &T, value: i32) -> Res<()> {
|
pub fn position(&mut self, kind: c_int, code: c_int, value: i32) -> Res<()> {
|
||||||
self.write(event.kind(), event.code(), value)
|
self.write(kind, code, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Device {
|
impl Drop for Device {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ui_dev_destroy(self.fd);
|
ui_dev_destroy(self.fd).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,254 +0,0 @@
|
|||||||
use libc::c_int;
|
|
||||||
use ffi::*;
|
|
||||||
use {Event};
|
|
||||||
use super::{Kind, Code};
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
|
||||||
pub enum Absolute {
|
|
||||||
Position(Position),
|
|
||||||
Wheel(Wheel),
|
|
||||||
Hat(Hat),
|
|
||||||
Digi(Digi),
|
|
||||||
Multi(Multi),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for Absolute {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Absolute(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl super::Position for Absolute { }
|
|
||||||
|
|
||||||
impl Kind for Absolute {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_ABS
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Absolute {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Absolute::Position(ref v) => v.code(),
|
|
||||||
&Absolute::Wheel(ref v) => v.code(),
|
|
||||||
&Absolute::Hat(ref v) => v.code(),
|
|
||||||
&Absolute::Digi(ref v) => v.code(),
|
|
||||||
&Absolute::Multi(ref v) => v.code(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(PositionVariants))]
|
|
||||||
pub enum Position {
|
|
||||||
X,
|
|
||||||
Y,
|
|
||||||
Z,
|
|
||||||
RX,
|
|
||||||
RY,
|
|
||||||
RZ,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for Position {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Absolute(Absolute::Position(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl super::Position for Position { }
|
|
||||||
|
|
||||||
impl Kind for Position {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_ABS
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Position {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Position::X => ABS_X,
|
|
||||||
&Position::Y => ABS_Y,
|
|
||||||
&Position::Z => ABS_Z,
|
|
||||||
&Position::RX => ABS_RX,
|
|
||||||
&Position::RY => ABS_RY,
|
|
||||||
&Position::RZ => ABS_RZ,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(WheelVariants))]
|
|
||||||
pub enum Wheel {
|
|
||||||
Throttle,
|
|
||||||
Rudder,
|
|
||||||
Position,
|
|
||||||
Gas,
|
|
||||||
Brake,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for Wheel {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Absolute(Absolute::Wheel(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl super::Position for Wheel { }
|
|
||||||
|
|
||||||
impl Kind for Wheel {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_ABS
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Wheel {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Wheel::Throttle => ABS_THROTTLE,
|
|
||||||
&Wheel::Rudder => ABS_RUDDER,
|
|
||||||
&Wheel::Position => ABS_WHEEL,
|
|
||||||
&Wheel::Gas => ABS_GAS,
|
|
||||||
&Wheel::Brake => ABS_BRAKE,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(HatVariants))]
|
|
||||||
pub enum Hat {
|
|
||||||
X0,
|
|
||||||
Y0,
|
|
||||||
X1,
|
|
||||||
Y1,
|
|
||||||
X2,
|
|
||||||
Y2,
|
|
||||||
X3,
|
|
||||||
Y3,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for Hat {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Absolute(Absolute::Hat(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl super::Position for Hat { }
|
|
||||||
|
|
||||||
impl Kind for Hat {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_ABS
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Hat {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Hat::X0 => ABS_HAT0X,
|
|
||||||
&Hat::Y0 => ABS_HAT0Y,
|
|
||||||
&Hat::X1 => ABS_HAT1X,
|
|
||||||
&Hat::Y1 => ABS_HAT1Y,
|
|
||||||
&Hat::X2 => ABS_HAT2X,
|
|
||||||
&Hat::Y2 => ABS_HAT2Y,
|
|
||||||
&Hat::X3 => ABS_HAT3X,
|
|
||||||
&Hat::Y3 => ABS_HAT3Y,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(DigiVariants))]
|
|
||||||
pub enum Digi {
|
|
||||||
Pressure,
|
|
||||||
Distance,
|
|
||||||
TiltX,
|
|
||||||
TiltY,
|
|
||||||
ToolWidth,
|
|
||||||
Volume,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for Digi {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Absolute(Absolute::Digi(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl super::Position for Digi { }
|
|
||||||
|
|
||||||
impl Kind for Digi {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_ABS
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Digi {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Digi::Pressure => ABS_PRESSURE,
|
|
||||||
&Digi::Distance => ABS_DISTANCE,
|
|
||||||
&Digi::TiltX => ABS_TILT_X,
|
|
||||||
&Digi::TiltY => ABS_TILT_Y,
|
|
||||||
&Digi::ToolWidth => ABS_TOOL_WIDTH,
|
|
||||||
&Digi::Volume => ABS_VOLUME,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(MultiVariants))]
|
|
||||||
pub enum Multi {
|
|
||||||
Slot,
|
|
||||||
TouchMajor,
|
|
||||||
TouchMinor,
|
|
||||||
WidthMajor,
|
|
||||||
WidthMinor,
|
|
||||||
Orientation,
|
|
||||||
PositionX,
|
|
||||||
PositionY,
|
|
||||||
ToolType,
|
|
||||||
BlobId,
|
|
||||||
TrackingId,
|
|
||||||
Pressure,
|
|
||||||
Distance,
|
|
||||||
ToolX,
|
|
||||||
ToolY,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for Multi {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Absolute(Absolute::Multi(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl super::Position for Multi { }
|
|
||||||
|
|
||||||
impl Kind for Multi {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_ABS
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Multi {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Multi::Slot => ABS_MT_SLOT,
|
|
||||||
&Multi::TouchMajor => ABS_MT_TOUCH_MAJOR,
|
|
||||||
&Multi::TouchMinor => ABS_MT_TOUCH_MINOR,
|
|
||||||
&Multi::WidthMajor => ABS_MT_WIDTH_MAJOR,
|
|
||||||
&Multi::WidthMinor => ABS_MT_WIDTH_MINOR,
|
|
||||||
&Multi::Orientation => ABS_MT_ORIENTATION,
|
|
||||||
&Multi::PositionX => ABS_MT_POSITION_X,
|
|
||||||
&Multi::PositionY => ABS_MT_POSITION_Y,
|
|
||||||
&Multi::ToolType => ABS_MT_TOOL_TYPE,
|
|
||||||
&Multi::BlobId => ABS_MT_BLOB_ID,
|
|
||||||
&Multi::TrackingId => ABS_MT_TRACKING_ID,
|
|
||||||
&Multi::Pressure => ABS_MT_PRESSURE,
|
|
||||||
&Multi::Distance => ABS_MT_DISTANCE,
|
|
||||||
&Multi::ToolX => ABS_MT_TOOL_X,
|
|
||||||
&Multi::ToolY => ABS_MT_TOOL_Y,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,483 +0,0 @@
|
|||||||
use libc::c_int;
|
|
||||||
use ffi::*;
|
|
||||||
use {Event};
|
|
||||||
use super::{Kind, Code, Press, Release};
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
|
||||||
pub enum Controller {
|
|
||||||
All,
|
|
||||||
Misc(Misc),
|
|
||||||
Mouse(Mouse),
|
|
||||||
JoyStick(JoyStick),
|
|
||||||
GamePad(GamePad),
|
|
||||||
Digi(Digi),
|
|
||||||
Wheel(Wheel),
|
|
||||||
DPad(DPad),
|
|
||||||
TriggerHappy(TriggerHappy),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for Controller {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Controller(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Press for Controller { }
|
|
||||||
impl Release for Controller { }
|
|
||||||
|
|
||||||
impl Kind for Controller {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_KEY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Controller {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Controller::All => unreachable!(),
|
|
||||||
|
|
||||||
&Controller::Misc(ref v) => v.code(),
|
|
||||||
&Controller::Mouse(ref v) => v.code(),
|
|
||||||
&Controller::JoyStick(ref v) => v.code(),
|
|
||||||
&Controller::GamePad(ref v) => v.code(),
|
|
||||||
&Controller::Digi(ref v) => v.code(),
|
|
||||||
&Controller::Wheel(ref v) => v.code(),
|
|
||||||
&Controller::DPad(ref v) => v.code(),
|
|
||||||
&Controller::TriggerHappy(ref v) => v.code(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(MiscVariants))]
|
|
||||||
pub enum Misc {
|
|
||||||
_0,
|
|
||||||
_1,
|
|
||||||
_2,
|
|
||||||
_3,
|
|
||||||
_4,
|
|
||||||
_5,
|
|
||||||
_6,
|
|
||||||
_7,
|
|
||||||
_8,
|
|
||||||
_9,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for Misc {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Controller(Controller::Misc(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Kind for Misc {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_KEY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Misc {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Misc::_0 => BTN_0,
|
|
||||||
&Misc::_1 => BTN_1,
|
|
||||||
&Misc::_2 => BTN_2,
|
|
||||||
&Misc::_3 => BTN_3,
|
|
||||||
&Misc::_4 => BTN_4,
|
|
||||||
&Misc::_5 => BTN_5,
|
|
||||||
&Misc::_6 => BTN_6,
|
|
||||||
&Misc::_7 => BTN_7,
|
|
||||||
&Misc::_8 => BTN_8,
|
|
||||||
&Misc::_9 => BTN_9,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(MouseVariants))]
|
|
||||||
pub enum Mouse {
|
|
||||||
Left,
|
|
||||||
Right,
|
|
||||||
Middle,
|
|
||||||
Side,
|
|
||||||
Extra,
|
|
||||||
Forward,
|
|
||||||
Back,
|
|
||||||
Task,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for Mouse {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Controller(Controller::Mouse(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Mouse {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Mouse::Left => BTN_LEFT,
|
|
||||||
&Mouse::Right => BTN_RIGHT,
|
|
||||||
&Mouse::Middle => BTN_MIDDLE,
|
|
||||||
&Mouse::Side => BTN_SIDE,
|
|
||||||
&Mouse::Extra => BTN_EXTRA,
|
|
||||||
&Mouse::Forward => BTN_FORWARD,
|
|
||||||
&Mouse::Back => BTN_BACK,
|
|
||||||
&Mouse::Task => BTN_TASK,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(JoyStickVariants))]
|
|
||||||
pub enum JoyStick {
|
|
||||||
Trigger,
|
|
||||||
Thumb,
|
|
||||||
Thumb2,
|
|
||||||
Top,
|
|
||||||
Top2,
|
|
||||||
Pinkie,
|
|
||||||
Base,
|
|
||||||
Base2,
|
|
||||||
Base3,
|
|
||||||
Base4,
|
|
||||||
Base5,
|
|
||||||
Base6,
|
|
||||||
Dead,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for JoyStick {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Controller(Controller::JoyStick(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Press for JoyStick { }
|
|
||||||
impl Release for JoyStick { }
|
|
||||||
|
|
||||||
impl Kind for JoyStick {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_KEY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for JoyStick {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&JoyStick::Trigger => BTN_TRIGGER,
|
|
||||||
&JoyStick::Thumb => BTN_THUMB,
|
|
||||||
&JoyStick::Thumb2 => BTN_THUMB2,
|
|
||||||
&JoyStick::Top => BTN_TOP,
|
|
||||||
&JoyStick::Top2 => BTN_TOP2,
|
|
||||||
&JoyStick::Pinkie => BTN_PINKIE,
|
|
||||||
&JoyStick::Base => BTN_BASE,
|
|
||||||
&JoyStick::Base2 => BTN_BASE2,
|
|
||||||
&JoyStick::Base3 => BTN_BASE3,
|
|
||||||
&JoyStick::Base4 => BTN_BASE4,
|
|
||||||
&JoyStick::Base5 => BTN_BASE5,
|
|
||||||
&JoyStick::Base6 => BTN_BASE6,
|
|
||||||
&JoyStick::Dead => BTN_DEAD,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(GamePadVariants))]
|
|
||||||
pub enum GamePad {
|
|
||||||
South,
|
|
||||||
A,
|
|
||||||
East,
|
|
||||||
B,
|
|
||||||
C,
|
|
||||||
North,
|
|
||||||
X,
|
|
||||||
West,
|
|
||||||
Y,
|
|
||||||
Z,
|
|
||||||
TL,
|
|
||||||
TR,
|
|
||||||
TL2,
|
|
||||||
TR2,
|
|
||||||
Select,
|
|
||||||
Start,
|
|
||||||
Mode,
|
|
||||||
ThumbL,
|
|
||||||
ThumbR,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for GamePad {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Controller(Controller::GamePad(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Press for GamePad { }
|
|
||||||
impl Release for GamePad { }
|
|
||||||
|
|
||||||
impl Kind for GamePad {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_KEY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for GamePad {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&GamePad::South => BTN_SOUTH,
|
|
||||||
&GamePad::A => BTN_A,
|
|
||||||
&GamePad::East => BTN_EAST,
|
|
||||||
&GamePad::B => BTN_B,
|
|
||||||
&GamePad::C => BTN_C,
|
|
||||||
&GamePad::North => BTN_NORTH,
|
|
||||||
&GamePad::X => BTN_X,
|
|
||||||
&GamePad::West => BTN_WEST,
|
|
||||||
&GamePad::Y => BTN_Y,
|
|
||||||
&GamePad::Z => BTN_Z,
|
|
||||||
&GamePad::TL => BTN_TL,
|
|
||||||
&GamePad::TR => BTN_TR,
|
|
||||||
&GamePad::TL2 => BTN_TL2,
|
|
||||||
&GamePad::TR2 => BTN_TR2,
|
|
||||||
&GamePad::Select => BTN_SELECT,
|
|
||||||
&GamePad::Start => BTN_START,
|
|
||||||
&GamePad::Mode => BTN_MODE,
|
|
||||||
&GamePad::ThumbL => BTN_THUMBL,
|
|
||||||
&GamePad::ThumbR => BTN_THUMBR,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(DigiVariants))]
|
|
||||||
pub enum Digi {
|
|
||||||
Pen,
|
|
||||||
Rubber,
|
|
||||||
Brush,
|
|
||||||
Pencil,
|
|
||||||
AirBrush,
|
|
||||||
Finger,
|
|
||||||
Mouse,
|
|
||||||
Lens,
|
|
||||||
QuintTap,
|
|
||||||
Touch,
|
|
||||||
Stylus,
|
|
||||||
Stylus2,
|
|
||||||
DoubleTap,
|
|
||||||
TripleTap,
|
|
||||||
QuadTap,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for Digi {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Controller(Controller::Digi(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Press for Digi { }
|
|
||||||
impl Release for Digi { }
|
|
||||||
|
|
||||||
impl Kind for Digi {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_KEY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Digi {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Digi::Pen => BTN_TOOL_PEN,
|
|
||||||
&Digi::Rubber => BTN_TOOL_RUBBER,
|
|
||||||
&Digi::Brush => BTN_TOOL_BRUSH,
|
|
||||||
&Digi::Pencil => BTN_TOOL_PENCIL,
|
|
||||||
&Digi::AirBrush => BTN_TOOL_AIRBRUSH,
|
|
||||||
&Digi::Finger => BTN_TOOL_FINGER,
|
|
||||||
&Digi::Mouse => BTN_TOOL_MOUSE,
|
|
||||||
&Digi::Lens => BTN_TOOL_LENS,
|
|
||||||
&Digi::QuintTap => BTN_TOOL_QUINTTAP,
|
|
||||||
&Digi::Touch => BTN_TOUCH,
|
|
||||||
&Digi::Stylus => BTN_STYLUS,
|
|
||||||
&Digi::Stylus2 => BTN_STYLUS2,
|
|
||||||
&Digi::DoubleTap => BTN_TOOL_DOUBLETAP,
|
|
||||||
&Digi::TripleTap => BTN_TOOL_TRIPLETAP,
|
|
||||||
&Digi::QuadTap => BTN_TOOL_QUADTAP,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(WheelVariants))]
|
|
||||||
pub enum Wheel {
|
|
||||||
GearDown,
|
|
||||||
GearUp,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for Wheel {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Controller(Controller::Wheel(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Press for Wheel { }
|
|
||||||
impl Release for Wheel { }
|
|
||||||
|
|
||||||
impl Kind for Wheel {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_KEY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Wheel {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Wheel::GearDown => BTN_GEAR_DOWN,
|
|
||||||
&Wheel::GearUp => BTN_GEAR_UP,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(DPadVariants))]
|
|
||||||
pub enum DPad {
|
|
||||||
Up,
|
|
||||||
Down,
|
|
||||||
Left,
|
|
||||||
Right,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for DPad {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Controller(Controller::DPad(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Press for DPad { }
|
|
||||||
impl Release for DPad { }
|
|
||||||
|
|
||||||
impl Kind for DPad {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_KEY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for DPad {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&DPad::Up => BTN_DPAD_UP,
|
|
||||||
&DPad::Down => BTN_DPAD_DOWN,
|
|
||||||
&DPad::Left => BTN_DPAD_LEFT,
|
|
||||||
&DPad::Right => BTN_DPAD_RIGHT,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(TriggerHappyVariants))]
|
|
||||||
pub enum TriggerHappy {
|
|
||||||
_1,
|
|
||||||
_2,
|
|
||||||
_3,
|
|
||||||
_4,
|
|
||||||
_5,
|
|
||||||
_6,
|
|
||||||
_7,
|
|
||||||
_8,
|
|
||||||
_9,
|
|
||||||
_10,
|
|
||||||
_11,
|
|
||||||
_12,
|
|
||||||
_13,
|
|
||||||
_14,
|
|
||||||
_15,
|
|
||||||
_16,
|
|
||||||
_17,
|
|
||||||
_18,
|
|
||||||
_19,
|
|
||||||
_20,
|
|
||||||
_21,
|
|
||||||
_22,
|
|
||||||
_23,
|
|
||||||
_24,
|
|
||||||
_25,
|
|
||||||
_26,
|
|
||||||
_27,
|
|
||||||
_28,
|
|
||||||
_29,
|
|
||||||
_30,
|
|
||||||
_31,
|
|
||||||
_32,
|
|
||||||
_33,
|
|
||||||
_34,
|
|
||||||
_35,
|
|
||||||
_36,
|
|
||||||
_37,
|
|
||||||
_38,
|
|
||||||
_39,
|
|
||||||
_40,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for TriggerHappy {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Controller(Controller::TriggerHappy(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Press for TriggerHappy { }
|
|
||||||
impl Release for TriggerHappy { }
|
|
||||||
|
|
||||||
impl Kind for TriggerHappy {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_KEY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for TriggerHappy {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&TriggerHappy::_1 => BTN_TRIGGER_HAPPY1,
|
|
||||||
&TriggerHappy::_2 => BTN_TRIGGER_HAPPY2,
|
|
||||||
&TriggerHappy::_3 => BTN_TRIGGER_HAPPY3,
|
|
||||||
&TriggerHappy::_4 => BTN_TRIGGER_HAPPY4,
|
|
||||||
&TriggerHappy::_5 => BTN_TRIGGER_HAPPY5,
|
|
||||||
&TriggerHappy::_6 => BTN_TRIGGER_HAPPY6,
|
|
||||||
&TriggerHappy::_7 => BTN_TRIGGER_HAPPY7,
|
|
||||||
&TriggerHappy::_8 => BTN_TRIGGER_HAPPY8,
|
|
||||||
&TriggerHappy::_9 => BTN_TRIGGER_HAPPY9,
|
|
||||||
&TriggerHappy::_10 => BTN_TRIGGER_HAPPY10,
|
|
||||||
&TriggerHappy::_11 => BTN_TRIGGER_HAPPY11,
|
|
||||||
&TriggerHappy::_12 => BTN_TRIGGER_HAPPY12,
|
|
||||||
&TriggerHappy::_13 => BTN_TRIGGER_HAPPY13,
|
|
||||||
&TriggerHappy::_14 => BTN_TRIGGER_HAPPY14,
|
|
||||||
&TriggerHappy::_15 => BTN_TRIGGER_HAPPY15,
|
|
||||||
&TriggerHappy::_16 => BTN_TRIGGER_HAPPY16,
|
|
||||||
&TriggerHappy::_17 => BTN_TRIGGER_HAPPY17,
|
|
||||||
&TriggerHappy::_18 => BTN_TRIGGER_HAPPY18,
|
|
||||||
&TriggerHappy::_19 => BTN_TRIGGER_HAPPY19,
|
|
||||||
&TriggerHappy::_20 => BTN_TRIGGER_HAPPY20,
|
|
||||||
&TriggerHappy::_21 => BTN_TRIGGER_HAPPY21,
|
|
||||||
&TriggerHappy::_22 => BTN_TRIGGER_HAPPY22,
|
|
||||||
&TriggerHappy::_23 => BTN_TRIGGER_HAPPY23,
|
|
||||||
&TriggerHappy::_24 => BTN_TRIGGER_HAPPY24,
|
|
||||||
&TriggerHappy::_25 => BTN_TRIGGER_HAPPY25,
|
|
||||||
&TriggerHappy::_26 => BTN_TRIGGER_HAPPY26,
|
|
||||||
&TriggerHappy::_27 => BTN_TRIGGER_HAPPY27,
|
|
||||||
&TriggerHappy::_28 => BTN_TRIGGER_HAPPY28,
|
|
||||||
&TriggerHappy::_29 => BTN_TRIGGER_HAPPY29,
|
|
||||||
&TriggerHappy::_30 => BTN_TRIGGER_HAPPY30,
|
|
||||||
&TriggerHappy::_31 => BTN_TRIGGER_HAPPY31,
|
|
||||||
&TriggerHappy::_32 => BTN_TRIGGER_HAPPY32,
|
|
||||||
&TriggerHappy::_33 => BTN_TRIGGER_HAPPY33,
|
|
||||||
&TriggerHappy::_34 => BTN_TRIGGER_HAPPY34,
|
|
||||||
&TriggerHappy::_35 => BTN_TRIGGER_HAPPY35,
|
|
||||||
&TriggerHappy::_36 => BTN_TRIGGER_HAPPY36,
|
|
||||||
&TriggerHappy::_37 => BTN_TRIGGER_HAPPY37,
|
|
||||||
&TriggerHappy::_38 => BTN_TRIGGER_HAPPY38,
|
|
||||||
&TriggerHappy::_39 => BTN_TRIGGER_HAPPY39,
|
|
||||||
&TriggerHappy::_40 => BTN_TRIGGER_HAPPY40,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,78 +0,0 @@
|
|||||||
use libc::c_int;
|
|
||||||
|
|
||||||
/// Trait for event type.
|
|
||||||
pub trait Kind {
|
|
||||||
/// Get the event type.
|
|
||||||
fn kind(&self) -> c_int;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Trait for event code.
|
|
||||||
pub trait Code {
|
|
||||||
/// Get the event code.
|
|
||||||
fn code(&self) -> c_int;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Trait for events that support pressing (namely keys).
|
|
||||||
pub trait Press: Kind + Code { }
|
|
||||||
|
|
||||||
/// Trait for events that support releasing (namely keys).
|
|
||||||
pub trait Release: Kind + Code { }
|
|
||||||
|
|
||||||
/// Trait for events that support absolute or relative positioning.
|
|
||||||
pub trait Position: Kind + Code { }
|
|
||||||
|
|
||||||
/// All supported events.
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
|
||||||
pub enum Event {
|
|
||||||
All,
|
|
||||||
|
|
||||||
/// Keyboard event.
|
|
||||||
Keyboard(Keyboard),
|
|
||||||
|
|
||||||
/// Controller event.
|
|
||||||
Controller(Controller),
|
|
||||||
|
|
||||||
/// Relative movement event.
|
|
||||||
Relative(Relative),
|
|
||||||
|
|
||||||
/// Absolute movement event.
|
|
||||||
Absolute(Absolute),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Kind for Event {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Event::All => unreachable!(),
|
|
||||||
|
|
||||||
&Event::Keyboard(ref v) => v.kind(),
|
|
||||||
&Event::Controller(ref v) => v.kind(),
|
|
||||||
&Event::Relative(ref v) => v.kind(),
|
|
||||||
&Event::Absolute(ref v) => v.kind(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Event {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Event::All => unreachable!(),
|
|
||||||
|
|
||||||
&Event::Keyboard(ref v) => v.code(),
|
|
||||||
&Event::Controller(ref v) => v.code(),
|
|
||||||
&Event::Relative(ref v) => v.code(),
|
|
||||||
&Event::Absolute(ref v) => v.code(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod keyboard;
|
|
||||||
pub use self::keyboard::Keyboard;
|
|
||||||
|
|
||||||
pub mod controller;
|
|
||||||
pub use self::controller::Controller;
|
|
||||||
|
|
||||||
pub mod relative;
|
|
||||||
pub use self::relative::Relative;
|
|
||||||
|
|
||||||
pub mod absolute;
|
|
||||||
pub use self::absolute::Absolute;
|
|
@ -1,105 +0,0 @@
|
|||||||
use libc::c_int;
|
|
||||||
use ffi::*;
|
|
||||||
use {Event};
|
|
||||||
use super::{Kind, Code};
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
|
||||||
pub enum Relative {
|
|
||||||
Position(Position),
|
|
||||||
Wheel(Wheel),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for Relative {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Relative(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl super::Position for Relative { }
|
|
||||||
|
|
||||||
impl Kind for Relative {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_REL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Relative {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Relative::Position(ref v) => v.code(),
|
|
||||||
&Relative::Wheel(ref v) => v.code(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(PositionVariants))]
|
|
||||||
pub enum Position {
|
|
||||||
X,
|
|
||||||
Y,
|
|
||||||
Z,
|
|
||||||
RX,
|
|
||||||
RY,
|
|
||||||
RZ,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for Position {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Relative(Relative::Position(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl super::Position for Position { }
|
|
||||||
|
|
||||||
impl Kind for Position {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_REL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Position {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Position::X => REL_X,
|
|
||||||
&Position::Y => REL_Y,
|
|
||||||
&Position::Z => REL_Z,
|
|
||||||
&Position::RX => REL_RX,
|
|
||||||
&Position::RY => REL_RY,
|
|
||||||
&Position::RZ => REL_RZ,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
custom_derive! {
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(WheelVariants))]
|
|
||||||
pub enum Wheel {
|
|
||||||
Horizontal,
|
|
||||||
Dial,
|
|
||||||
Vertical,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Event> for Wheel {
|
|
||||||
fn into(self) -> Event {
|
|
||||||
Event::Relative(Relative::Wheel(self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl super::Position for Wheel { }
|
|
||||||
|
|
||||||
impl Kind for Wheel {
|
|
||||||
fn kind(&self) -> c_int {
|
|
||||||
EV_REL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Code for Wheel {
|
|
||||||
fn code(&self) -> c_int {
|
|
||||||
match self {
|
|
||||||
&Wheel::Horizontal => REL_HWHEEL,
|
|
||||||
&Wheel::Dial => REL_DIAL,
|
|
||||||
&Wheel::Vertical => REL_WHEEL,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
10
src/lib.rs
10
src/lib.rs
@ -4,15 +4,8 @@ extern crate libc;
|
|||||||
|
|
||||||
extern crate uinput_sys as ffi;
|
extern crate uinput_sys as ffi;
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate nix;
|
extern crate nix;
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate custom_derive;
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate enum_derive;
|
|
||||||
|
|
||||||
#[cfg(feature = "udev")]
|
#[cfg(feature = "udev")]
|
||||||
extern crate libudev as udev;
|
extern crate libudev as udev;
|
||||||
|
|
||||||
@ -23,9 +16,6 @@ pub use error::Error;
|
|||||||
|
|
||||||
pub type Result<T> = ::std::result::Result<T, Error>;
|
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||||
|
|
||||||
pub mod event;
|
|
||||||
pub use event::Event;
|
|
||||||
|
|
||||||
pub mod device;
|
pub mod device;
|
||||||
pub use device::Device;
|
pub use device::Device;
|
||||||
|
|
||||||
|
@ -1,17 +1,22 @@
|
|||||||
extern crate uinput;
|
extern crate uinput;
|
||||||
use uinput::event::keyboard;
|
extern crate uinput_sys as ffi;
|
||||||
|
|
||||||
|
use ffi::*;
|
||||||
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut device = uinput::default().unwrap()
|
let mut device = uinput::default().expect("1")
|
||||||
.name("test").unwrap()
|
.name("test").expect("2")
|
||||||
.event(uinput::event::Keyboard::All).unwrap()
|
.event().expect("3")
|
||||||
.create().unwrap();
|
//.event(uinput::event::Keyboard::All).unwrap()
|
||||||
|
.create().expect("4");
|
||||||
|
|
||||||
thread::sleep(Duration::from_secs(1));
|
thread::sleep(Duration::from_secs(1));
|
||||||
|
|
||||||
|
device.click(EV_KEY, KEY_H).unwrap();
|
||||||
|
/*
|
||||||
device.click(&keyboard::Key::H).unwrap();
|
device.click(&keyboard::Key::H).unwrap();
|
||||||
device.click(&keyboard::Key::E).unwrap();
|
device.click(&keyboard::Key::E).unwrap();
|
||||||
device.click(&keyboard::Key::L).unwrap();
|
device.click(&keyboard::Key::L).unwrap();
|
||||||
@ -24,6 +29,7 @@ fn main() {
|
|||||||
device.click(&keyboard::Key::L).unwrap();
|
device.click(&keyboard::Key::L).unwrap();
|
||||||
device.click(&keyboard::Key::D).unwrap();
|
device.click(&keyboard::Key::D).unwrap();
|
||||||
device.click(&keyboard::Key::Enter).unwrap();
|
device.click(&keyboard::Key::Enter).unwrap();
|
||||||
|
*/
|
||||||
|
|
||||||
device.synchronize().unwrap();
|
device.synchronize().unwrap();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user