diff --git a/src/error.rs b/src/error.rs index ce2c568..3b9ff0e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,4 @@ -use std::fmt; -use std::error; -use std::ffi; -use std::io; +use std::{error, ffi, fmt, io}; #[cfg(target_os = "linux")] use nix; @@ -9,66 +6,66 @@ use nix; /// UInput error. #[derive(Debug)] pub enum Error { - /// System errors. - #[cfg(target_os = "linux")] - Nix(nix::Error), + /// System errors. + #[cfg(target_os = "linux")] + Nix(nix::Error), - /// Errors with internal nulls in names. - Nul(ffi::NulError), + /// Errors with internal nulls in names. + Nul(ffi::NulError), - Io(io::Error), - - #[cfg(feature = "toml_serde")] - Toml(toml::de::Error), + Io(io::Error), - NotAKeyboard, - - /// error reading input_event - ShortRead, + #[cfg(feature = "toml_serde")] + Toml(toml::de::Error), - /// epoll already added - EpollAlreadyAdded, + NotAKeyboard, + + /// error reading input_event + ShortRead, + + /// epoll already added + EpollAlreadyAdded, } impl From for Error { - fn from(value: ffi::NulError) -> Self { - Error::Nul(value) - } + fn from(value: ffi::NulError) -> Self { + Error::Nul(value) + } } #[cfg(target_os = "linux")] impl From for Error { - fn from(value: nix::Error) -> Self { - Error::Nix(value) - } + fn from(value: nix::Error) -> Self { + Error::Nix(value) + } } impl From for Error { - fn from(value: io::Error) -> Self { - Error::Io(value) - } + fn from(value: io::Error) -> Self { + Error::Io(value) + } } impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - match self { - #[cfg(target_os = "linux")] - &Error::Nix(ref err) => err.fmt(f), + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match self { + #[cfg(target_os = "linux")] + &Error::Nix(ref err) => err.fmt(f), - &Error::Nul(ref err) => err.fmt(f), + &Error::Nul(ref err) => err.fmt(f), - &Error::Io(ref err) => err.fmt(f), + &Error::Io(ref err) => err.fmt(f), - #[cfg(feature = "toml_serde")] - &Error::Toml(ref err) => err.fmt(f), - - &Error::NotAKeyboard => f.write_str("This device file is not a keyboard"), + #[cfg(feature = "toml_serde")] + &Error::Toml(ref err) => err.fmt(f), - &Error::ShortRead => f.write_str("Error while reading from device file."), - - &Error::EpollAlreadyAdded => f.write_str("epoll already added, delete first"), - } - } + &Error::NotAKeyboard => f.write_str("This device file is not a keyboard"), + + &Error::ShortRead => f.write_str("Error while reading from device file."), + + &Error::EpollAlreadyAdded => f.write_str("epoll already added, delete first"), + } + } } impl error::Error for Error {} diff --git a/src/keymapper.rs b/src/keymapper.rs index 1da05b8..9ca913f 100644 --- a/src/keymapper.rs +++ b/src/keymapper.rs @@ -1,7 +1,4 @@ - -use std::collections::HashMap; -use std::hash::Hash; -use std::convert::TryFrom; +use std::{collections::HashMap, convert::TryFrom, hash::Hash}; #[cfg(feature = "toml_serde")] use std::path::Path; @@ -23,17 +20,17 @@ pub enum KeyState { } pub trait KeyEvent - where - T: Into, +where + T: Into, { fn code(&self) -> T; fn value(&self) -> KeyState; } pub trait Keyboard - where - T: Into + Copy, - E: KeyEvent, +where + T: Into + Copy, + E: KeyEvent, { fn send(&self, event: &mut E) -> Result; fn send_mod_code(&self, code: T, event: &mut E) -> Result; @@ -44,7 +41,14 @@ pub trait Keyboard fn caps_lock_code(&self) -> T; fn block_key(&self) -> Result; - fn send_half_inverted_key(&self, half_inverted_key: &HalfInvertedKey, event: &mut E, left_shift: bool, right_shift: bool, caps_lock: bool) -> Result { + fn send_half_inverted_key( + &self, + half_inverted_key: &HalfInvertedKey, + event: &mut E, + left_shift: bool, + right_shift: bool, + caps_lock: bool, + ) -> Result { let value = event.value(); let mut invert_shift = half_inverted_key.invert_shift; if value == KeyState::DOWN { @@ -87,19 +91,19 @@ pub trait Keyboard } pub trait KeyMapper - where - T: Into + Copy, - E: KeyEvent, - K: Keyboard, +where + T: Into + Copy, + E: KeyEvent, + K: Keyboard, { fn send_event(&self, key_state: &[bool], event: &mut E, device: &K) -> Result; } pub struct KeyMaps - where - T: Into + Copy + Clone + Eq + Hash, - E: KeyEvent, - K: Keyboard, +where + T: Into + Copy + Clone + Eq + Hash, + E: KeyEvent, + K: Keyboard, { keymaps: Vec>>, keymap_index_keys: HashMap, @@ -113,17 +117,25 @@ pub struct KeyMaps } fn parse_key(key_map: &HashMap<&'static str, T>, key: &str) -> T { - match key_map.get(key.trim_matches(|c: char| c.is_whitespace() || c == INVERT_KEY_FLAG || c == CAPS_MODIFY_KEY_FLAG)) { + match key_map.get(key.trim_matches(|c: char| { + c.is_whitespace() || c == INVERT_KEY_FLAG || c == CAPS_MODIFY_KEY_FLAG + })) { Some(key_code) => *key_code, - None => panic!("unknown key: {}", key.trim()) + None => panic!("unknown key: {}", key.trim()), } } -fn parse_keymap_numeric(key_map: &HashMap<&'static str, T>, keymap: &str) -> Vec { +fn parse_keymap_numeric( + key_map: &HashMap<&'static str, T>, + keymap: &str, +) -> Vec { keymap.split(",").map(|k| parse_key(key_map, k)).collect() } -fn parse_key_half_inverted(key_map: &HashMap<&'static str, T>, key: &str) -> HalfInvertedKey { +fn parse_key_half_inverted( + key_map: &HashMap<&'static str, T>, + key: &str, +) -> HalfInvertedKey { HalfInvertedKey { code: parse_key(key_map, key), invert_shift: key.contains(INVERT_KEY_FLAG), @@ -138,53 +150,70 @@ fn parse_keymap_u16(key_map: &HashMap<&'static str, T>, keymap: // todo: how do I return an iterator here instead of .collect to Vec? fn parse_keymap(key_map: &HashMap<&'static str, T>, keymap: &str) -> Vec> { - keymap.split(",").map(|k| { - let ret: Key = if k.contains(HALF_KEY_SEPARATOR) { - let keys: Vec<&str> = k.split(HALF_KEY_SEPARATOR).collect(); - if keys.len() != 2 { - panic!("split key can only have 2 keys, 1 :, has {} keys", keys.len()); - } - let mut shift_half = parse_key_half_inverted(key_map, keys[1]); - shift_half.invert_shift = !shift_half.invert_shift; - Key::FullKey(parse_key_half_inverted(key_map, keys[0]), shift_half) - } else if k.contains(INVERT_KEY_FLAG) || k.contains(CAPS_MODIFY_KEY_FLAG) { - Key::HalfKey(parse_key_half_inverted(key_map, k)) - } else { - Key::Direct(parse_key(key_map, k)) - }; - ret - }).collect() + keymap + .split(",") + .map(|k| { + let ret: Key = if k.contains(HALF_KEY_SEPARATOR) { + let keys: Vec<&str> = k.split(HALF_KEY_SEPARATOR).collect(); + if keys.len() != 2 { + panic!( + "split key can only have 2 keys, 1 :, has {} keys", + keys.len() + ); + } + let mut shift_half = parse_key_half_inverted(key_map, keys[1]); + shift_half.invert_shift = !shift_half.invert_shift; + Key::FullKey(parse_key_half_inverted(key_map, keys[0]), shift_half) + } else if k.contains(INVERT_KEY_FLAG) || k.contains(CAPS_MODIFY_KEY_FLAG) { + Key::HalfKey(parse_key_half_inverted(key_map, k)) + } else { + Key::Direct(parse_key(key_map, k)) + }; + ret + }) + .collect() } impl KeyMaps - where - T: Into + TryFrom + Copy + Clone + Eq + Hash + Default + 'static, - E: KeyEvent, - K: Keyboard, +where + T: Into + TryFrom + Copy + Clone + Eq + Hash + Default + 'static, + E: KeyEvent, + K: Keyboard, { #[cfg(feature = "toml_serde")] - pub fn from_cfg>(key_map: &HashMap<&'static str, T>, path: P) -> KeyMaps { + pub fn from_cfg>( + key_map: &HashMap<&'static str, T>, + path: P, + ) -> KeyMaps { let key_map_config = parse_cfg(path).expect("provided config cannot be found/parsed"); KeyMaps::new(key_map, key_map_config) } pub fn new(key_map: &HashMap<&'static str, T>, config: KeymapConfig) -> KeyMaps { if config.keymaps.len() < 2 { - panic!("must have at least 2 keymaps (original and mapped) but only have {},", config.keymaps.len()); + panic!( + "must have at least 2 keymaps (original and mapped) but only have {},", + config.keymaps.len() + ); } - if config.default_keymap_index >= config.keymaps.len() || config.revert_keymap_index >= config.keymaps.len() { + if config.default_keymap_index >= config.keymaps.len() + || config.revert_keymap_index >= config.keymaps.len() + { panic!("default_keymap_index ({}) and revert_keymap_index ({}) must be less than keymaps length ({}),", config.default_keymap_index, config.revert_keymap_index, config.keymaps.len()); } let base_keymap = parse_keymap_numeric(key_map, &config.keymaps[0]); //println!("base_keymap : {:?}", base_keymap); - let mut keymaps: Vec>> = vec!(Box::new(Key::Noop)); // todo: can we share the box? + let mut keymaps: Vec>> = vec![Box::new(Key::Noop)]; // todo: can we share the box? let mut keymap_index_keys: HashMap = HashMap::new(); for (x, v) in config.keymaps.iter().enumerate() { keymap_index_keys.insert(*key_map.get(&*x.to_string()).unwrap(), x); if x == 0 { continue; } - if v.contains(HALF_KEY_SEPARATOR) || v.contains(INVERT_KEY_FLAG) || v.contains(CAPS_MODIFY_KEY_FLAG) { + if v.contains(HALF_KEY_SEPARATOR) + || v.contains(INVERT_KEY_FLAG) + || v.contains(CAPS_MODIFY_KEY_FLAG) + { // we need KeyMap, the complicated more memory taking one let v = parse_keymap(key_map, v); let mut keymap = KeyMap::new(); @@ -241,7 +270,11 @@ impl KeyMaps KeyMaps { keymaps: keymaps, keymap_index_keys: keymap_index_keys, - switch_layout_keys: config.switch_layout_keys.iter().map(|k| parse_key(key_map, k).into()).collect(), + switch_layout_keys: config + .switch_layout_keys + .iter() + .map(|k| parse_key(key_map, k).into()) + .collect(), key_state: [false; KEY_MAX], // todo: detect key state? at least CAPSLOCK... revert_default_keys, @@ -250,17 +283,18 @@ impl KeyMaps current_keymap_index: config.default_keymap_index, } } -//} + //} -//impl KeyMapper for KeyMaps { -//impl KeyMaps { -pub fn send_event(&mut self, mut event: &mut E, device: &K) -> Result { - let value = event.value(); - if value != KeyState::OTHER { + //impl KeyMapper for KeyMaps { + //impl KeyMaps { + pub fn send_event(&mut self, mut event: &mut E, device: &K) -> Result { + let value = event.value(); + if value != KeyState::OTHER { // todo: index check here... - if event.code() == device.caps_lock_code() { - if value == KeyState::DOWN { - self.key_state[device.caps_lock_code().into()] = !self.key_state[device.caps_lock_code().into()]; + if event.code() == device.caps_lock_code() { + if value == KeyState::DOWN { + self.key_state[device.caps_lock_code().into()] = + !self.key_state[device.caps_lock_code().into()]; } } else { let idx = event.code().into(); @@ -286,28 +320,35 @@ pub fn send_event(&mut self, mut event: &mut E, device: &K) -> Result { return device.block_key(); // we don't want to also send this keypress, so bail } } - if self.revert_default_keys.contains(&event.code()) { - match value { - KeyState::DOWN => { - // todo: should we release currently held keys and then press them back down here, kinda the opposite of below? not for now... - self.current_keymap_index = self.revert_keymap_index - }, - KeyState::UP => { - self.current_keymap_index = self.chosen_keymap_index; - #[cfg(not(target_os = "macos"))] { - // need to release all currently held down keys, except this one, otherwise ctrl+c will get c stuck because code c value 1 will be sent, but then we'll let go of ctrl, and code j value 0 is sent, so c is never released - let orig_code = event.code(); - for (idx, key_down) in self.key_state.iter_mut().enumerate() { - if *key_down { - device.send_mod_code_value(T::try_from(idx).unwrap_or_else(|_| panic!("cannot convert from usize to T ????")), true, event)?; - *key_down = false; + if self.revert_default_keys.contains(&event.code()) { + match value { + KeyState::DOWN => { + // todo: should we release currently held keys and then press them back down here, kinda the opposite of below? not for now... + self.current_keymap_index = self.revert_keymap_index + } + KeyState::UP => { + self.current_keymap_index = self.chosen_keymap_index; + #[cfg(not(target_os = "macos"))] + { + // need to release all currently held down keys, except this one, otherwise ctrl+c will get c stuck because code c value 1 will be sent, but then we'll let go of ctrl, and code j value 0 is sent, so c is never released + let orig_code = event.code(); + for (idx, key_down) in self.key_state.iter_mut().enumerate() { + if *key_down { + device.send_mod_code_value( + T::try_from(idx).unwrap_or_else(|_| { + panic!("cannot convert from usize to T ????") + }), + true, + event, + )?; + *key_down = false; + } + } + // todo: seems like we should not send this here, and instead just set the original code back, and pass it through the keymaps? + return device.send_mod_code_value(orig_code, true, event); } } - // todo: seems like we should not send this here, and instead just set the original code back, and pass it through the keymaps? - return device.send_mod_code_value(orig_code, true, event) - } - }, - _ => () // do nothing for 2 + _ => (), // do nothing for 2 } } } @@ -325,7 +366,7 @@ struct KeyMap + Copy> { impl + Copy> KeyMap { pub fn new() -> Self { KeyMap { - keymap: [Key::Noop; KEY_MAX] + keymap: [Key::Noop; KEY_MAX], } } @@ -335,10 +376,10 @@ impl + Copy> KeyMap { } impl KeyMapper for KeyMap - where - T: Into + Copy, - E: KeyEvent, - K: Keyboard, +where + T: Into + Copy, + E: KeyEvent, + K: Keyboard, { fn send_event(&self, key_state: &[bool], event: &mut E, device: &K) -> Result { self.keymap[event.code().into()].send_event(key_state, event, device) @@ -356,9 +397,7 @@ impl + TryFrom + Copy + Default> CodeKeyMap { *v = T::try_from(x).unwrap_or_else(|_| panic!("cannot convert from usize to T ????")); } //println!("keymap: {:?}", &keymap[..]); - CodeKeyMap { - keymap - } + CodeKeyMap { keymap } } pub fn map(&mut self, from: T, to: T) { @@ -367,10 +406,10 @@ impl + TryFrom + Copy + Default> CodeKeyMap { } impl KeyMapper for CodeKeyMap - where - T: Into + TryFrom + Copy + Default, - E: KeyEvent, - K: Keyboard, +where + T: Into + TryFrom + Copy + Default, + E: KeyEvent, + K: Keyboard, { fn send_event(&self, _key_state: &[bool], event: &mut E, device: &K) -> Result { device.send_mod_code(self.keymap[event.code().into()], event) @@ -390,10 +429,10 @@ pub struct HalfInvertedKey { } impl KeyMapper for HalfInvertedKey - where - T: Into + Clone + Copy, - E: KeyEvent, - K: Keyboard, +where + T: Into + Clone + Copy, + E: KeyEvent, + K: Keyboard, { fn send_event(&self, key_state: &[bool], event: &mut E, device: &K) -> Result { let left_shift = key_state[device.left_shift_code().into()]; @@ -405,8 +444,8 @@ impl KeyMapper for HalfInvertedKey #[derive(Clone, Copy)] enum Key - where - T: Copy + Clone +where + T: Copy + Clone, { Noop, Direct(T), @@ -415,32 +454,38 @@ enum Key } impl KeyMapper for Key - where - T: Into + Copy, - E: KeyEvent, - K: Keyboard, +where + T: Into + Copy, + E: KeyEvent, + K: Keyboard, { fn send_event(&self, key_state: &[bool], event: &mut E, device: &K) -> Result { match *self { - Key::Noop => { - device.send(event) - }, - Key::Direct(code) => { - device.send_mod_code(code, event) - }, - Key::HalfKey(ref key_half) => { - key_half.send_event(key_state, event, device) - }, + Key::Noop => device.send(event), + Key::Direct(code) => device.send_mod_code(code, event), + Key::HalfKey(ref key_half) => key_half.send_event(key_state, event, device), Key::FullKey(ref noshift_half, ref shift_half) => { let left_shift = key_state[device.left_shift_code().into()]; let right_shift = key_state[device.right_shift_code().into()]; let caps_lock = key_state[device.caps_lock_code().into()]; if caps_lock != (left_shift || right_shift) { - device.send_half_inverted_key(shift_half, event, left_shift, right_shift, caps_lock) + device.send_half_inverted_key( + shift_half, + event, + left_shift, + right_shift, + caps_lock, + ) } else { - device.send_half_inverted_key(noshift_half, event, left_shift, right_shift, caps_lock) + device.send_half_inverted_key( + noshift_half, + event, + left_shift, + right_shift, + caps_lock, + ) } - }, + } } } } @@ -453,7 +498,7 @@ pub struct KeymapConfig { revert_default_keys: Option>, revert_keymap_index: usize, default_keymap_index: usize, - keymaps: Vec + keymaps: Vec, } #[cfg(feature = "toml_serde")] @@ -473,7 +518,7 @@ pub struct KeymapConfig { revert_default_keys: Option>, revert_keymap_index: usize, default_keymap_index: usize, - keymaps: Vec<&'static str> + keymaps: Vec<&'static str>, } #[cfg(not(feature = "toml_serde"))] @@ -528,4 +573,3 @@ impl Default for KeymapConfig { } } } - diff --git a/src/linux/device/builder.rs b/src/linux/device/builder.rs index ec7e467..fdc726e 100644 --- a/src/linux/device/builder.rs +++ b/src/linux/device/builder.rs @@ -1,12 +1,7 @@ -use std::path::Path; -use std::{mem, slice}; -use std::ffi::CString; +use crate::{Device, Result}; use libc::c_int; -use nix::{self, fcntl, unistd, ioctl_write_ptr, ioctl_none}; -use nix::sys::stat; -use crate::{Result, Device}; -use std::collections::hash_map::Values; -use std::os::raw::c_char; +use nix::{self, fcntl, ioctl_none, ioctl_write_ptr, sys::stat, unistd}; +use std::{collections::hash_map::Values, ffi::CString, mem, os::raw::c_char, path::Path, slice}; use crate::linux::device::codes::*; @@ -21,131 +16,134 @@ pub const ABS_CNT: c_int = ABS_MAX + 1; #[derive(Clone, Copy)] #[repr(C)] pub struct input_id { - pub bustype: u16, - pub vendor: u16, - pub product: u16, - pub version: u16, + pub bustype: u16, + pub vendor: u16, + pub product: u16, + pub version: u16, } #[repr(C)] pub struct uinput_user_dev { - pub name: [c_char; UINPUT_MAX_NAME_SIZE as usize], - pub id: input_id, + pub name: [c_char; UINPUT_MAX_NAME_SIZE as usize], + pub id: input_id, - pub ff_effects_max: u32, - pub absmax: [i32; ABS_CNT as usize], - pub absmin: [i32; ABS_CNT as usize], - pub absfuzz: [i32; ABS_CNT as usize], - pub absflat: [i32; ABS_CNT as usize], + pub ff_effects_max: u32, + pub absmax: [i32; ABS_CNT as usize], + pub absmin: [i32; ABS_CNT as usize], + pub absfuzz: [i32; ABS_CNT as usize], + pub absflat: [i32; ABS_CNT as usize], } /// Device builder. pub struct Builder { - fd: c_int, - def: uinput_user_dev, - abs: Option, + fd: c_int, + def: uinput_user_dev, + abs: Option, } impl Builder { - /// Create a builder from the specified path. - pub fn open>(path: P) -> Result { - Ok(Builder { - fd: fcntl::open(path.as_ref(), fcntl::OFlag::O_WRONLY | fcntl::OFlag::O_NONBLOCK, stat::Mode::empty())?, - def: unsafe { mem::zeroed() }, - abs: None, - }) - } + /// Create a builder from the specified path. + pub fn open>(path: P) -> Result { + Ok(Builder { + fd: fcntl::open( + path.as_ref(), + fcntl::OFlag::O_WRONLY | fcntl::OFlag::O_NONBLOCK, + stat::Mode::empty(), + )?, + def: unsafe { mem::zeroed() }, + abs: None, + }) + } - /// Create a builder from `/dev/uinput`. - pub fn default() -> Result { - Builder::open("/dev/uinput") - } + /// Create a builder from `/dev/uinput`. + pub fn default() -> Result { + Builder::open("/dev/uinput") + } - /// Set the name. - pub fn name>(mut self, value: T) -> Result { - let string = CString::new(value.as_ref())?; - let bytes = string.as_bytes_with_nul(); + /// Set the name. + pub fn name>(mut self, value: T) -> Result { + let string = CString::new(value.as_ref())?; + let bytes = string.as_bytes_with_nul(); - if bytes.len() > UINPUT_MAX_NAME_SIZE as usize { - Err(nix::Error::EINVAL)?; - } + if bytes.len() > UINPUT_MAX_NAME_SIZE as usize { + Err(nix::Error::EINVAL)?; + } - (&mut self.def.name)[..bytes.len()] - .clone_from_slice(unsafe { mem::transmute(bytes) }); + (&mut self.def.name)[..bytes.len()].clone_from_slice(unsafe { mem::transmute(bytes) }); - Ok(self) - } + Ok(self) + } - /// Set the bus type. - pub fn bus(mut self, value: u16) -> Self { - self.def.id.bustype = value; - self - } + /// Set the bus type. + pub fn bus(mut self, value: u16) -> Self { + self.def.id.bustype = value; + self + } - /// Set the vendor ID. - pub fn vendor(mut self, value: u16) -> Self { - self.def.id.vendor = value; - self - } + /// Set the vendor ID. + pub fn vendor(mut self, value: u16) -> Self { + self.def.id.vendor = value; + self + } - /// Set the product ID. - pub fn product(mut self, value: u16) -> Self { - self.def.id.product = value; - self - } + /// Set the product ID. + pub fn product(mut self, value: u16) -> Self { + self.def.id.product = value; + self + } - /// Set the version. - pub fn version(mut self, value: u16) -> Self { - self.def.id.version = value; - self - } + /// Set the version. + pub fn version(mut self, value: u16) -> Self { + self.def.id.version = value; + self + } - pub fn event(mut self, key_codes: Values<&str, u16>) -> Result { - self.abs = None; - unsafe { - ui_set_evbit(self.fd, EV_KEY as *const c_int)?; + pub fn event(mut self, key_codes: Values<&str, u16>) -> Result { + self.abs = None; + unsafe { + ui_set_evbit(self.fd, EV_KEY as *const c_int)?; - for key_code in key_codes { - ui_set_keybit(self.fd, *key_code as *const c_int)?; - } - } - Ok(self) - } + for key_code in key_codes { + ui_set_keybit(self.fd, *key_code as *const c_int)?; + } + } + Ok(self) + } - /// Set the maximum value for the previously enabled absolute event. - pub fn max(mut self, value: i32) -> Self { - self.def.absmax[self.abs.unwrap() as usize] = value; - self - } + /// Set the maximum value for the previously enabled absolute event. + pub fn max(mut self, value: i32) -> Self { + self.def.absmax[self.abs.unwrap() as usize] = value; + self + } - /// Set the minimum value for the previously enabled absolute event. - pub fn min(mut self, value: i32) -> Self { - self.def.absmin[self.abs.unwrap() as usize] = value; - self - } + /// Set the minimum value for the previously enabled absolute event. + pub fn min(mut self, value: i32) -> Self { + self.def.absmin[self.abs.unwrap() as usize] = value; + self + } - /// Set the fuzz value for the previously enabled absolute event. - pub fn fuzz(mut self, value: i32) -> Self { - self.def.absfuzz[self.abs.unwrap() as usize] = value; - self - } + /// Set the fuzz value for the previously enabled absolute event. + pub fn fuzz(mut self, value: i32) -> Self { + self.def.absfuzz[self.abs.unwrap() as usize] = value; + self + } - /// Set the flat value for the previously enabled absolute event. - pub fn flat(mut self, value: i32) -> Self { - self.def.absflat[self.abs.unwrap() as usize] = value; - self - } + /// Set the flat value for the previously enabled absolute event. + pub fn flat(mut self, value: i32) -> Self { + self.def.absflat[self.abs.unwrap() as usize] = value; + self + } - /// Create the defined device. - pub fn create(self) -> Result { - unsafe { - let ptr = &self.def as *const _ as *const u8; - let size = mem::size_of_val(&self.def); + /// Create the defined device. + pub fn create(self) -> Result { + unsafe { + let ptr = &self.def as *const _ as *const u8; + let size = mem::size_of_val(&self.def); - unistd::write(self.fd, slice::from_raw_parts(ptr, size))?; - ui_dev_create(self.fd)?; - } + unistd::write(self.fd, slice::from_raw_parts(ptr, size))?; + ui_dev_create(self.fd)?; + } - Ok(Device::new(self.fd)) - } + Ok(Device::new(self.fd)) + } } diff --git a/src/linux/device/codes.rs b/src/linux/device/codes.rs index 95628f4..0424baf 100644 --- a/src/linux/device/codes.rs +++ b/src/linux/device/codes.rs @@ -1,12 +1,12 @@ -use libc::{c_int}; +use libc::c_int; -pub const INPUT_PROP_POINTER: c_int = 0x00; /* needs a pointer */ -pub const INPUT_PROP_DIRECT: c_int = 0x01; /* direct input devices */ -pub const INPUT_PROP_BUTTONPAD: c_int = 0x02; /* has button: c_int = s under pad */ -pub const INPUT_PROP_SEMI_MT: c_int = 0x03; /* touch rectangle only */ -pub const INPUT_PROP_TOPBUTTONPAD: c_int = 0x04; /* softbuttons at top of pad */ +pub const INPUT_PROP_POINTER: c_int = 0x00; /* needs a pointer */ +pub const INPUT_PROP_DIRECT: c_int = 0x01; /* direct input devices */ +pub const INPUT_PROP_BUTTONPAD: c_int = 0x02; /* has button: c_int = s under pad */ +pub const INPUT_PROP_SEMI_MT: c_int = 0x03; /* touch rectangle only */ +pub const INPUT_PROP_TOPBUTTONPAD: c_int = 0x04; /* softbuttons at top of pad */ pub const INPUT_PROP_POINTING_STICK: c_int = 0x05; /* is a pointing stick */ -pub const INPUT_PROP_ACCELEROMETER: c_int = 0x06; /* has accelerometer */ +pub const INPUT_PROP_ACCELEROMETER: c_int = 0x06; /* has accelerometer */ pub const INPUT_PROP_MAX: c_int = 0x1f; pub const INPUT_PROP_CNT: c_int = INPUT_PROP_MAX + 1; @@ -15,31 +15,31 @@ pub const INPUT_PROP_CNT: c_int = INPUT_PROP_MAX + 1; * Event types */ -pub const EV_SYN: c_int = 0x00; -pub const EV_KEY: c_int = 0x01; -pub const EV_REL: c_int = 0x02; -pub const EV_ABS: c_int = 0x03; -pub const EV_MSC: c_int = 0x04; -pub const EV_SW: c_int = 0x05; -pub const EV_LED: c_int = 0x11; -pub const EV_SND: c_int = 0x12; -pub const EV_REP: c_int = 0x14; -pub const EV_FF: c_int = 0x15; -pub const EV_PWR: c_int = 0x16; +pub const EV_SYN: c_int = 0x00; +pub const EV_KEY: c_int = 0x01; +pub const EV_REL: c_int = 0x02; +pub const EV_ABS: c_int = 0x03; +pub const EV_MSC: c_int = 0x04; +pub const EV_SW: c_int = 0x05; +pub const EV_LED: c_int = 0x11; +pub const EV_SND: c_int = 0x12; +pub const EV_REP: c_int = 0x14; +pub const EV_FF: c_int = 0x15; +pub const EV_PWR: c_int = 0x16; pub const EV_FF_STATUS: c_int = 0x17; -pub const EV_MAX: c_int = 0x1f; -pub const EV_CNT: c_int = EV_MAX + 1; +pub const EV_MAX: c_int = 0x1f; +pub const EV_CNT: c_int = EV_MAX + 1; /* * Synchronization events. */ -pub const SYN_REPORT: c_int = 0; -pub const SYN_CONFIG: c_int = 1; +pub const SYN_REPORT: c_int = 0; +pub const SYN_CONFIG: c_int = 1; pub const SYN_MT_REPORT: c_int = 2; -pub const SYN_DROPPED: c_int = 3; -pub const SYN_MAX: c_int = 0xf; -pub const SYN_CNT: c_int = SYN_MAX + 1; +pub const SYN_DROPPED: c_int = 3; +pub const SYN_MAX: c_int = 0xf; +pub const SYN_CNT: c_int = SYN_MAX + 1; /* * Keys and buttons @@ -52,194 +52,194 @@ pub const SYN_CNT: c_int = SYN_MAX + 1; * SC - System Control */ -pub const KEY_RESERVED: c_int = 0; -pub const KEY_ESC: c_int = 1; -pub const KEY_1: c_int = 2; -pub const KEY_2: c_int = 3; -pub const KEY_3: c_int = 4; -pub const KEY_4: c_int = 5; -pub const KEY_5: c_int = 6; -pub const KEY_6: c_int = 7; -pub const KEY_7: c_int = 8; -pub const KEY_8: c_int = 9; -pub const KEY_9: c_int = 10; -pub const KEY_10: c_int = 11; -pub const KEY_MINUS: c_int = 12; -pub const KEY_EQUAL: c_int = 13; -pub const KEY_BACKSPACE: c_int = 14; -pub const KEY_TAB: c_int = 15; -pub const KEY_Q: c_int = 16; -pub const KEY_W: c_int = 17; -pub const KEY_E: c_int = 18; -pub const KEY_R: c_int = 19; -pub const KEY_T: c_int = 20; -pub const KEY_Y: c_int = 21; -pub const KEY_U: c_int = 22; -pub const KEY_I: c_int = 23; -pub const KEY_O: c_int = 24; -pub const KEY_P: c_int = 25; -pub const KEY_LEFTBRACE: c_int = 26; +pub const KEY_RESERVED: c_int = 0; +pub const KEY_ESC: c_int = 1; +pub const KEY_1: c_int = 2; +pub const KEY_2: c_int = 3; +pub const KEY_3: c_int = 4; +pub const KEY_4: c_int = 5; +pub const KEY_5: c_int = 6; +pub const KEY_6: c_int = 7; +pub const KEY_7: c_int = 8; +pub const KEY_8: c_int = 9; +pub const KEY_9: c_int = 10; +pub const KEY_10: c_int = 11; +pub const KEY_MINUS: c_int = 12; +pub const KEY_EQUAL: c_int = 13; +pub const KEY_BACKSPACE: c_int = 14; +pub const KEY_TAB: c_int = 15; +pub const KEY_Q: c_int = 16; +pub const KEY_W: c_int = 17; +pub const KEY_E: c_int = 18; +pub const KEY_R: c_int = 19; +pub const KEY_T: c_int = 20; +pub const KEY_Y: c_int = 21; +pub const KEY_U: c_int = 22; +pub const KEY_I: c_int = 23; +pub const KEY_O: c_int = 24; +pub const KEY_P: c_int = 25; +pub const KEY_LEFTBRACE: c_int = 26; pub const KEY_RIGHTBRACE: c_int = 27; -pub const KEY_ENTER: c_int = 28; -pub const KEY_LEFTCTRL: c_int = 29; -pub const KEY_A: c_int = 30; -pub const KEY_S: c_int = 31; -pub const KEY_D: c_int = 32; -pub const KEY_F: c_int = 33; -pub const KEY_G: c_int = 34; -pub const KEY_H: c_int = 35; -pub const KEY_J: c_int = 36; -pub const KEY_K: c_int = 37; -pub const KEY_L: c_int = 38; -pub const KEY_SEMICOLON: c_int = 39; +pub const KEY_ENTER: c_int = 28; +pub const KEY_LEFTCTRL: c_int = 29; +pub const KEY_A: c_int = 30; +pub const KEY_S: c_int = 31; +pub const KEY_D: c_int = 32; +pub const KEY_F: c_int = 33; +pub const KEY_G: c_int = 34; +pub const KEY_H: c_int = 35; +pub const KEY_J: c_int = 36; +pub const KEY_K: c_int = 37; +pub const KEY_L: c_int = 38; +pub const KEY_SEMICOLON: c_int = 39; pub const KEY_APOSTROPHE: c_int = 40; -pub const KEY_GRAVE: c_int = 41; -pub const KEY_LEFTSHIFT: c_int = 42; -pub const KEY_BACKSLASH: c_int = 43; -pub const KEY_Z: c_int = 44; -pub const KEY_X: c_int = 45; -pub const KEY_C: c_int = 46; -pub const KEY_V: c_int = 47; -pub const KEY_B: c_int = 48; -pub const KEY_N: c_int = 49; -pub const KEY_M: c_int = 50; -pub const KEY_COMMA: c_int = 51; -pub const KEY_DOT: c_int = 52; -pub const KEY_SLASH: c_int = 53; +pub const KEY_GRAVE: c_int = 41; +pub const KEY_LEFTSHIFT: c_int = 42; +pub const KEY_BACKSLASH: c_int = 43; +pub const KEY_Z: c_int = 44; +pub const KEY_X: c_int = 45; +pub const KEY_C: c_int = 46; +pub const KEY_V: c_int = 47; +pub const KEY_B: c_int = 48; +pub const KEY_N: c_int = 49; +pub const KEY_M: c_int = 50; +pub const KEY_COMMA: c_int = 51; +pub const KEY_DOT: c_int = 52; +pub const KEY_SLASH: c_int = 53; pub const KEY_RIGHTSHIFT: c_int = 54; pub const KEY_KPASTERISK: c_int = 55; -pub const KEY_LEFTALT: c_int = 56; -pub const KEY_SPACE: c_int = 57; -pub const KEY_CAPSLOCK: c_int = 58; -pub const KEY_F1: c_int = 59; -pub const KEY_F2: c_int = 60; -pub const KEY_F3: c_int = 61; -pub const KEY_F4: c_int = 62; -pub const KEY_F5: c_int = 63; -pub const KEY_F6: c_int = 64; -pub const KEY_F7: c_int = 65; -pub const KEY_F8: c_int = 66; -pub const KEY_F9: c_int = 67; -pub const KEY_F10: c_int = 68; -pub const KEY_NUMLOCK: c_int = 69; +pub const KEY_LEFTALT: c_int = 56; +pub const KEY_SPACE: c_int = 57; +pub const KEY_CAPSLOCK: c_int = 58; +pub const KEY_F1: c_int = 59; +pub const KEY_F2: c_int = 60; +pub const KEY_F3: c_int = 61; +pub const KEY_F4: c_int = 62; +pub const KEY_F5: c_int = 63; +pub const KEY_F6: c_int = 64; +pub const KEY_F7: c_int = 65; +pub const KEY_F8: c_int = 66; +pub const KEY_F9: c_int = 67; +pub const KEY_F10: c_int = 68; +pub const KEY_NUMLOCK: c_int = 69; pub const KEY_SCROLLLOCK: c_int = 70; -pub const KEY_KP7: c_int = 71; -pub const KEY_KP8: c_int = 72; -pub const KEY_KP9: c_int = 73; -pub const KEY_KPMINUS: c_int = 74; -pub const KEY_KP4: c_int = 75; -pub const KEY_KP5: c_int = 76; -pub const KEY_KP6: c_int = 77; -pub const KEY_KPPLUS: c_int = 78; -pub const KEY_KP1: c_int = 79; -pub const KEY_KP2: c_int = 80; -pub const KEY_KP3: c_int = 81; -pub const KEY_KP0: c_int = 82; -pub const KEY_KPDOT: c_int = 83; +pub const KEY_KP7: c_int = 71; +pub const KEY_KP8: c_int = 72; +pub const KEY_KP9: c_int = 73; +pub const KEY_KPMINUS: c_int = 74; +pub const KEY_KP4: c_int = 75; +pub const KEY_KP5: c_int = 76; +pub const KEY_KP6: c_int = 77; +pub const KEY_KPPLUS: c_int = 78; +pub const KEY_KP1: c_int = 79; +pub const KEY_KP2: c_int = 80; +pub const KEY_KP3: c_int = 81; +pub const KEY_KP0: c_int = 82; +pub const KEY_KPDOT: c_int = 83; -pub const KEY_ZENKAKUHANKAKU: c_int = 85; -pub const KEY_102ND: c_int = 86; -pub const KEY_F11: c_int = 87; -pub const KEY_F12: c_int = 88; -pub const KEY_RO: c_int = 89; -pub const KEY_KATAKANA: c_int = 90; -pub const KEY_HIRAGANA: c_int = 91; -pub const KEY_HENKAN: c_int = 92; +pub const KEY_ZENKAKUHANKAKU: c_int = 85; +pub const KEY_102ND: c_int = 86; +pub const KEY_F11: c_int = 87; +pub const KEY_F12: c_int = 88; +pub const KEY_RO: c_int = 89; +pub const KEY_KATAKANA: c_int = 90; +pub const KEY_HIRAGANA: c_int = 91; +pub const KEY_HENKAN: c_int = 92; pub const KEY_KATAKANAHIRAGANA: c_int = 93; -pub const KEY_MUHENKAN: c_int = 94; -pub const KEY_KPJPCOMMA: c_int = 95; -pub const KEY_KPENTER: c_int = 96; -pub const KEY_RIGHTCTRL: c_int = 97; -pub const KEY_KPSLASH: c_int = 98; -pub const KEY_SYSRQ: c_int = 99; -pub const KEY_RIGHTALT: c_int = 100; -pub const KEY_LINEFEED: c_int = 101; -pub const KEY_HOME: c_int = 102; -pub const KEY_UP: c_int = 103; -pub const KEY_PAGEUP: c_int = 104; -pub const KEY_LEFT: c_int = 105; -pub const KEY_RIGHT: c_int = 106; -pub const KEY_END: c_int = 107; -pub const KEY_DOWN: c_int = 108; -pub const KEY_PAGEDOWN: c_int = 109; -pub const KEY_INSERT: c_int = 110; -pub const KEY_DELETE: c_int = 111; -pub const KEY_MACRO: c_int = 112; -pub const KEY_MUTE: c_int = 113; -pub const KEY_VOLUMEDOWN: c_int = 114; -pub const KEY_VOLUMEUP: c_int = 115; -pub const KEY_POWER: c_int = 116; /* SC System Power Down */ -pub const KEY_KPEQUAL: c_int = 117; -pub const KEY_KPPLUSMINUS: c_int = 118; -pub const KEY_PAUSE: c_int = 119; -pub const KEY_SCALE: c_int = 120; /* AL Compiz Scale : c_int = Expose */ +pub const KEY_MUHENKAN: c_int = 94; +pub const KEY_KPJPCOMMA: c_int = 95; +pub const KEY_KPENTER: c_int = 96; +pub const KEY_RIGHTCTRL: c_int = 97; +pub const KEY_KPSLASH: c_int = 98; +pub const KEY_SYSRQ: c_int = 99; +pub const KEY_RIGHTALT: c_int = 100; +pub const KEY_LINEFEED: c_int = 101; +pub const KEY_HOME: c_int = 102; +pub const KEY_UP: c_int = 103; +pub const KEY_PAGEUP: c_int = 104; +pub const KEY_LEFT: c_int = 105; +pub const KEY_RIGHT: c_int = 106; +pub const KEY_END: c_int = 107; +pub const KEY_DOWN: c_int = 108; +pub const KEY_PAGEDOWN: c_int = 109; +pub const KEY_INSERT: c_int = 110; +pub const KEY_DELETE: c_int = 111; +pub const KEY_MACRO: c_int = 112; +pub const KEY_MUTE: c_int = 113; +pub const KEY_VOLUMEDOWN: c_int = 114; +pub const KEY_VOLUMEUP: c_int = 115; +pub const KEY_POWER: c_int = 116; /* SC System Power Down */ +pub const KEY_KPEQUAL: c_int = 117; +pub const KEY_KPPLUSMINUS: c_int = 118; +pub const KEY_PAUSE: c_int = 119; +pub const KEY_SCALE: c_int = 120; /* AL Compiz Scale : c_int = Expose */ -pub const KEY_KPCOMMA: c_int = 121; -pub const KEY_HANGEUL: c_int = 122; -pub const KEY_HANGUEL: c_int = KEY_HANGEUL; -pub const KEY_HANJA: c_int = 123; -pub const KEY_YEN: c_int = 124; -pub const KEY_LEFTMETA: c_int = 125; +pub const KEY_KPCOMMA: c_int = 121; +pub const KEY_HANGEUL: c_int = 122; +pub const KEY_HANGUEL: c_int = KEY_HANGEUL; +pub const KEY_HANJA: c_int = 123; +pub const KEY_YEN: c_int = 124; +pub const KEY_LEFTMETA: c_int = 125; pub const KEY_RIGHTMETA: c_int = 126; -pub const KEY_COMPOSE: c_int = 127; +pub const KEY_COMPOSE: c_int = 127; -pub const KEY_STOP: c_int = 128; /* AC Stop */ -pub const KEY_AGAIN: c_int = 129; -pub const KEY_PROPS: c_int = 130; /* AC Properties */ -pub const KEY_UNDO: c_int = 131; /* AC Undo */ -pub const KEY_FRONT: c_int = 132; -pub const KEY_COPY: c_int = 133; /* AC Copy */ -pub const KEY_OPEN: c_int = 134; /* AC Open */ -pub const KEY_PASTE: c_int = 135; /* AC Paste */ -pub const KEY_FIND: c_int = 136; /* AC Search */ -pub const KEY_CUT: c_int = 137; /* AC Cut */ -pub const KEY_HELP: c_int = 138; /* AL Integrated Help Center */ -pub const KEY_MENU: c_int = 139; /* Menu : c_int = show menu */ -pub const KEY_CALC: c_int = 140; /* AL Calculator */ -pub const KEY_SETUP: c_int = 141; -pub const KEY_SLEEP: c_int = 142; /* SC System Sleep */ -pub const KEY_WAKEUP: c_int = 143; /* System Wake Up */ -pub const KEY_FILE: c_int = 144; /* AL Local Machine Browser */ -pub const KEY_SENDFILE: c_int = 145; -pub const KEY_DELETEFILE: c_int = 146; -pub const KEY_XFER: c_int = 147; -pub const KEY_PROG1: c_int = 148; -pub const KEY_PROG2: c_int = 149; -pub const KEY_WWW: c_int = 150; /* AL Internet Browser */ -pub const KEY_MSDOS: c_int = 151; -pub const KEY_COFFEE: c_int = 152; /* AL Terminal Lock/Screensaver */ -pub const KEY_SCREENLOCK: c_int = KEY_COFFEE; +pub const KEY_STOP: c_int = 128; /* AC Stop */ +pub const KEY_AGAIN: c_int = 129; +pub const KEY_PROPS: c_int = 130; /* AC Properties */ +pub const KEY_UNDO: c_int = 131; /* AC Undo */ +pub const KEY_FRONT: c_int = 132; +pub const KEY_COPY: c_int = 133; /* AC Copy */ +pub const KEY_OPEN: c_int = 134; /* AC Open */ +pub const KEY_PASTE: c_int = 135; /* AC Paste */ +pub const KEY_FIND: c_int = 136; /* AC Search */ +pub const KEY_CUT: c_int = 137; /* AC Cut */ +pub const KEY_HELP: c_int = 138; /* AL Integrated Help Center */ +pub const KEY_MENU: c_int = 139; /* Menu : c_int = show menu */ +pub const KEY_CALC: c_int = 140; /* AL Calculator */ +pub const KEY_SETUP: c_int = 141; +pub const KEY_SLEEP: c_int = 142; /* SC System Sleep */ +pub const KEY_WAKEUP: c_int = 143; /* System Wake Up */ +pub const KEY_FILE: c_int = 144; /* AL Local Machine Browser */ +pub const KEY_SENDFILE: c_int = 145; +pub const KEY_DELETEFILE: c_int = 146; +pub const KEY_XFER: c_int = 147; +pub const KEY_PROG1: c_int = 148; +pub const KEY_PROG2: c_int = 149; +pub const KEY_WWW: c_int = 150; /* AL Internet Browser */ +pub const KEY_MSDOS: c_int = 151; +pub const KEY_COFFEE: c_int = 152; /* AL Terminal Lock/Screensaver */ +pub const KEY_SCREENLOCK: c_int = KEY_COFFEE; pub const KEY_ROTATE_DISPLAY: c_int = 153; /* Display orientation for e.g. tablets */ -pub const KEY_DIRECTION: c_int = KEY_ROTATE_DISPLAY; -pub const KEY_CYCLEWINDOWS: c_int = 154; -pub const KEY_MAIL: c_int = 155; -pub const KEY_BOOKMARKS: c_int = 156; /* AC Bookmarks */ -pub const KEY_COMPUTER: c_int = 157; -pub const KEY_BACK: c_int = 158; /* AC Back */ -pub const KEY_FORWARD: c_int = 159; /* AC Forward */ -pub const KEY_CLOSECD: c_int = 160; -pub const KEY_EJECTCD: c_int = 161; -pub const KEY_EJECTCLOSECD: c_int = 162; -pub const KEY_NEXTSONG: c_int = 163; -pub const KEY_PLAYPAUSE: c_int = 164; -pub const KEY_PREVIOUSSONG: c_int = 165; -pub const KEY_STOPCD: c_int = 166; -pub const KEY_RECORD: c_int = 167; -pub const KEY_REWIND: c_int = 168; -pub const KEY_PHONE: c_int = 169; /* Media Select Telephone */ -pub const KEY_ISO: c_int = 170; -pub const KEY_CONFIG: c_int = 171; /* AL Consumer Control Configuration */ -pub const KEY_HOMEPAGE: c_int = 172; /* AC Home */ -pub const KEY_REFRESH: c_int = 173; /* AC Refresh */ -pub const KEY_EXIT: c_int = 174; /* AC Exit */ -pub const KEY_MOVE: c_int = 175; -pub const KEY_EDIT: c_int = 176; -pub const KEY_SCROLLUP: c_int = 177; -pub const KEY_SCROLLDOWN: c_int = 178; -pub const KEY_KPLEFTPAREN: c_int = 179; -pub const KEY_KPRIGHTPAREN: c_int = 180; -pub const KEY_NEW: c_int = 181; /* AC New */ -pub const KEY_REDO: c_int = 182; /* AC Redo/Repeat */ +pub const KEY_DIRECTION: c_int = KEY_ROTATE_DISPLAY; +pub const KEY_CYCLEWINDOWS: c_int = 154; +pub const KEY_MAIL: c_int = 155; +pub const KEY_BOOKMARKS: c_int = 156; /* AC Bookmarks */ +pub const KEY_COMPUTER: c_int = 157; +pub const KEY_BACK: c_int = 158; /* AC Back */ +pub const KEY_FORWARD: c_int = 159; /* AC Forward */ +pub const KEY_CLOSECD: c_int = 160; +pub const KEY_EJECTCD: c_int = 161; +pub const KEY_EJECTCLOSECD: c_int = 162; +pub const KEY_NEXTSONG: c_int = 163; +pub const KEY_PLAYPAUSE: c_int = 164; +pub const KEY_PREVIOUSSONG: c_int = 165; +pub const KEY_STOPCD: c_int = 166; +pub const KEY_RECORD: c_int = 167; +pub const KEY_REWIND: c_int = 168; +pub const KEY_PHONE: c_int = 169; /* Media Select Telephone */ +pub const KEY_ISO: c_int = 170; +pub const KEY_CONFIG: c_int = 171; /* AL Consumer Control Configuration */ +pub const KEY_HOMEPAGE: c_int = 172; /* AC Home */ +pub const KEY_REFRESH: c_int = 173; /* AC Refresh */ +pub const KEY_EXIT: c_int = 174; /* AC Exit */ +pub const KEY_MOVE: c_int = 175; +pub const KEY_EDIT: c_int = 176; +pub const KEY_SCROLLUP: c_int = 177; +pub const KEY_SCROLLDOWN: c_int = 178; +pub const KEY_KPLEFTPAREN: c_int = 179; +pub const KEY_KPRIGHTPAREN: c_int = 180; +pub const KEY_NEW: c_int = 181; /* AC New */ +pub const KEY_REDO: c_int = 182; /* AC Redo/Repeat */ pub const KEY_F13: c_int = 183; pub const KEY_F14: c_int = 184; @@ -254,62 +254,62 @@ pub const KEY_F22: c_int = 192; pub const KEY_F23: c_int = 193; pub const KEY_F24: c_int = 194; -pub const KEY_PLAYCD: c_int = 200; -pub const KEY_PAUSECD: c_int = 201; -pub const KEY_PROG3: c_int = 202; -pub const KEY_PROG4: c_int = 203; -pub const KEY_DASHBOARD: c_int = 204; /* AL Dashboard */ -pub const KEY_SUSPEND: c_int = 205; -pub const KEY_CLOSE: c_int = 206; /* AC Close */ -pub const KEY_PLAY: c_int = 207; -pub const KEY_FASTFORWARD: c_int = 208; -pub const KEY_BASSBOOST: c_int = 209; -pub const KEY_PRINT: c_int = 210; /* AC Print */ -pub const KEY_HP: c_int = 211; -pub const KEY_CAMERA: c_int = 212; -pub const KEY_SOUND: c_int = 213; -pub const KEY_QUESTION: c_int = 214; -pub const KEY_EMAIL: c_int = 215; -pub const KEY_CHAT: c_int = 216; -pub const KEY_SEARCH: c_int = 217; -pub const KEY_CONNECT: c_int = 218; -pub const KEY_FINANCE: c_int = 219; /* AL Checkbook/Finance */ -pub const KEY_SPORT: c_int = 220; -pub const KEY_SHOP: c_int = 221; -pub const KEY_ALTERASE: c_int = 222; -pub const KEY_CANCEL: c_int = 223; /* AC Cancel */ +pub const KEY_PLAYCD: c_int = 200; +pub const KEY_PAUSECD: c_int = 201; +pub const KEY_PROG3: c_int = 202; +pub const KEY_PROG4: c_int = 203; +pub const KEY_DASHBOARD: c_int = 204; /* AL Dashboard */ +pub const KEY_SUSPEND: c_int = 205; +pub const KEY_CLOSE: c_int = 206; /* AC Close */ +pub const KEY_PLAY: c_int = 207; +pub const KEY_FASTFORWARD: c_int = 208; +pub const KEY_BASSBOOST: c_int = 209; +pub const KEY_PRINT: c_int = 210; /* AC Print */ +pub const KEY_HP: c_int = 211; +pub const KEY_CAMERA: c_int = 212; +pub const KEY_SOUND: c_int = 213; +pub const KEY_QUESTION: c_int = 214; +pub const KEY_EMAIL: c_int = 215; +pub const KEY_CHAT: c_int = 216; +pub const KEY_SEARCH: c_int = 217; +pub const KEY_CONNECT: c_int = 218; +pub const KEY_FINANCE: c_int = 219; /* AL Checkbook/Finance */ +pub const KEY_SPORT: c_int = 220; +pub const KEY_SHOP: c_int = 221; +pub const KEY_ALTERASE: c_int = 222; +pub const KEY_CANCEL: c_int = 223; /* AC Cancel */ pub const KEY_BRIGHTNESSDOWN: c_int = 224; -pub const KEY_BRIGHTNESSUP: c_int = 225; -pub const KEY_MEDIA: c_int = 226; +pub const KEY_BRIGHTNESSUP: c_int = 225; +pub const KEY_MEDIA: c_int = 226; pub const KEY_SWITCHVIDEOMODE: c_int = 227; /* Cycle between available video outputs (Monitor/LCD/TV-out/etc) */ -pub const KEY_KBDILLUMTOGGLE: c_int = 228; -pub const KEY_KBDILLUMDOWN: c_int = 229; -pub const KEY_KBDILLUMUP: c_int = 230; +pub const KEY_KBDILLUMTOGGLE: c_int = 228; +pub const KEY_KBDILLUMDOWN: c_int = 229; +pub const KEY_KBDILLUMUP: c_int = 230; -pub const KEY_SEND: c_int = 231; /* AC Send */ -pub const KEY_REPLY: c_int = 232; /* AC Reply */ +pub const KEY_SEND: c_int = 231; /* AC Send */ +pub const KEY_REPLY: c_int = 232; /* AC Reply */ pub const KEY_FORWARDMAIL: c_int = 233; /* AC Forward Msg */ -pub const KEY_SAVE: c_int = 234; /* AC Save */ -pub const KEY_DOCUMENTS: c_int = 235; +pub const KEY_SAVE: c_int = 234; /* AC Save */ +pub const KEY_DOCUMENTS: c_int = 235; pub const KEY_BATTERY: c_int = 236; pub const KEY_BLUETOOTH: c_int = 237; -pub const KEY_WLAN: c_int = 238; -pub const KEY_UWB: c_int = 239; +pub const KEY_WLAN: c_int = 238; +pub const KEY_UWB: c_int = 239; pub const KEY_UNKNOWN: c_int = 240; -pub const KEY_VIDEO_NEXT: c_int = 241; /* drive next video source */ -pub const KEY_VIDEO_PREV: c_int = 242; /* drive previous video source */ +pub const KEY_VIDEO_NEXT: c_int = 241; /* drive next video source */ +pub const KEY_VIDEO_PREV: c_int = 242; /* drive previous video source */ pub const KEY_BRIGHTNESS_CYCLE: c_int = 243; /* brightness up, after max is min */ -pub const KEY_BRIGHTNESS_AUTO: c_int = 244; /* Set Auto Brightness: manual brightness control is off, rely on ambient */ -pub const KEY_BRIGHTNESS_ZERO: c_int = KEY_BRIGHTNESS_AUTO; -pub const KEY_DISPLAY_OFF: c_int = 245; /* display device to off state */ +pub const KEY_BRIGHTNESS_AUTO: c_int = 244; /* Set Auto Brightness: manual brightness control is off, rely on ambient */ +pub const KEY_BRIGHTNESS_ZERO: c_int = KEY_BRIGHTNESS_AUTO; +pub const KEY_DISPLAY_OFF: c_int = 245; /* display device to off state */ -pub const KEY_WWAN: c_int = 246; /* Wireless WAN : c_int = LTE, UMTS, GSM, etc. */ -pub const KEY_WIMAX: c_int = KEY_WWAN; +pub const KEY_WWAN: c_int = 246; /* Wireless WAN : c_int = LTE, UMTS, GSM, etc. */ +pub const KEY_WIMAX: c_int = KEY_WWAN; pub const KEY_RFKILL: c_int = 247; /* Key that controls all radios */ pub const KEY_MICMUTE: c_int = 248; /* Mute / unmute the microphone */ @@ -317,288 +317,288 @@ pub const KEY_MICMUTE: c_int = 248; /* Mute / unmute the microphone */ /* Code 255 is reserved for special needs of AT keyboard driver */ pub const BTN_MISC: c_int = 0x100; -pub const BTN_0: c_int = 0x100; -pub const BTN_1: c_int = 0x101; -pub const BTN_2: c_int = 0x102; -pub const BTN_3: c_int = 0x103; -pub const BTN_4: c_int = 0x104; -pub const BTN_5: c_int = 0x105; -pub const BTN_6: c_int = 0x106; -pub const BTN_7: c_int = 0x107; -pub const BTN_8: c_int = 0x108; -pub const BTN_9: c_int = 0x109; +pub const BTN_0: c_int = 0x100; +pub const BTN_1: c_int = 0x101; +pub const BTN_2: c_int = 0x102; +pub const BTN_3: c_int = 0x103; +pub const BTN_4: c_int = 0x104; +pub const BTN_5: c_int = 0x105; +pub const BTN_6: c_int = 0x106; +pub const BTN_7: c_int = 0x107; +pub const BTN_8: c_int = 0x108; +pub const BTN_9: c_int = 0x109; -pub const BTN_MOUSE: c_int = 0x110; -pub const BTN_LEFT: c_int = 0x110; -pub const BTN_RIGHT: c_int = 0x111; -pub const BTN_MIDDLE: c_int = 0x112; -pub const BTN_SIDE: c_int = 0x113; -pub const BTN_EXTRA: c_int = 0x114; +pub const BTN_MOUSE: c_int = 0x110; +pub const BTN_LEFT: c_int = 0x110; +pub const BTN_RIGHT: c_int = 0x111; +pub const BTN_MIDDLE: c_int = 0x112; +pub const BTN_SIDE: c_int = 0x113; +pub const BTN_EXTRA: c_int = 0x114; pub const BTN_FORWARD: c_int = 0x115; -pub const BTN_BACK: c_int = 0x116; -pub const BTN_TASK: c_int = 0x117; +pub const BTN_BACK: c_int = 0x116; +pub const BTN_TASK: c_int = 0x117; pub const BTN_JOYSTICK: c_int = 0x120; -pub const BTN_TRIGGER: c_int = 0x120; -pub const BTN_THUMB: c_int = 0x121; -pub const BTN_THUMB2: c_int = 0x122; -pub const BTN_TOP: c_int = 0x123; -pub const BTN_TOP2: c_int = 0x124; -pub const BTN_PINKIE: c_int = 0x125; -pub const BTN_BASE: c_int = 0x126; -pub const BTN_BASE2: c_int = 0x127; -pub const BTN_BASE3: c_int = 0x128; -pub const BTN_BASE4: c_int = 0x129; -pub const BTN_BASE5: c_int = 0x12a; -pub const BTN_BASE6: c_int = 0x12b; -pub const BTN_DEAD: c_int = 0x12f; +pub const BTN_TRIGGER: c_int = 0x120; +pub const BTN_THUMB: c_int = 0x121; +pub const BTN_THUMB2: c_int = 0x122; +pub const BTN_TOP: c_int = 0x123; +pub const BTN_TOP2: c_int = 0x124; +pub const BTN_PINKIE: c_int = 0x125; +pub const BTN_BASE: c_int = 0x126; +pub const BTN_BASE2: c_int = 0x127; +pub const BTN_BASE3: c_int = 0x128; +pub const BTN_BASE4: c_int = 0x129; +pub const BTN_BASE5: c_int = 0x12a; +pub const BTN_BASE6: c_int = 0x12b; +pub const BTN_DEAD: c_int = 0x12f; pub const BTN_GAMEPAD: c_int = 0x130; -pub const BTN_SOUTH: c_int = 0x130; -pub const BTN_A: c_int = BTN_SOUTH; -pub const BTN_EAST: c_int = 0x131; -pub const BTN_B: c_int = BTN_EAST; -pub const BTN_C: c_int = 0x132; -pub const BTN_NORTH: c_int = 0x133; -pub const BTN_X: c_int = BTN_NORTH; -pub const BTN_WEST: c_int = 0x134; -pub const BTN_Y: c_int = BTN_WEST; -pub const BTN_Z: c_int = 0x135; -pub const BTN_TL: c_int = 0x136; -pub const BTN_TR: c_int = 0x137; -pub const BTN_TL2: c_int = 0x138; -pub const BTN_TR2: c_int = 0x139; -pub const BTN_SELECT: c_int = 0x13a; -pub const BTN_START: c_int = 0x13b; -pub const BTN_MODE: c_int = 0x13c; -pub const BTN_THUMBL: c_int = 0x13d; -pub const BTN_THUMBR: c_int = 0x13e; +pub const BTN_SOUTH: c_int = 0x130; +pub const BTN_A: c_int = BTN_SOUTH; +pub const BTN_EAST: c_int = 0x131; +pub const BTN_B: c_int = BTN_EAST; +pub const BTN_C: c_int = 0x132; +pub const BTN_NORTH: c_int = 0x133; +pub const BTN_X: c_int = BTN_NORTH; +pub const BTN_WEST: c_int = 0x134; +pub const BTN_Y: c_int = BTN_WEST; +pub const BTN_Z: c_int = 0x135; +pub const BTN_TL: c_int = 0x136; +pub const BTN_TR: c_int = 0x137; +pub const BTN_TL2: c_int = 0x138; +pub const BTN_TR2: c_int = 0x139; +pub const BTN_SELECT: c_int = 0x13a; +pub const BTN_START: c_int = 0x13b; +pub const BTN_MODE: c_int = 0x13c; +pub const BTN_THUMBL: c_int = 0x13d; +pub const BTN_THUMBR: c_int = 0x13e; -pub const BTN_DIGI: c_int = 0x140; -pub const BTN_TOOL_PEN: c_int = 0x140; -pub const BTN_TOOL_RUBBER: c_int = 0x141; -pub const BTN_TOOL_BRUSH: c_int = 0x142; -pub const BTN_TOOL_PENCIL: c_int = 0x143; -pub const BTN_TOOL_AIRBRUSH: c_int = 0x144; -pub const BTN_TOOL_FINGER: c_int = 0x145; -pub const BTN_TOOL_MOUSE: c_int = 0x146; -pub const BTN_TOOL_LENS: c_int = 0x147; -pub const BTN_TOOL_QUINTTAP: c_int = 0x148; /* Five fingers on trackpad */ -pub const BTN_TOUCH: c_int = 0x14a; -pub const BTN_STYLUS: c_int = 0x14b; -pub const BTN_STYLUS2: c_int = 0x14c; +pub const BTN_DIGI: c_int = 0x140; +pub const BTN_TOOL_PEN: c_int = 0x140; +pub const BTN_TOOL_RUBBER: c_int = 0x141; +pub const BTN_TOOL_BRUSH: c_int = 0x142; +pub const BTN_TOOL_PENCIL: c_int = 0x143; +pub const BTN_TOOL_AIRBRUSH: c_int = 0x144; +pub const BTN_TOOL_FINGER: c_int = 0x145; +pub const BTN_TOOL_MOUSE: c_int = 0x146; +pub const BTN_TOOL_LENS: c_int = 0x147; +pub const BTN_TOOL_QUINTTAP: c_int = 0x148; /* Five fingers on trackpad */ +pub const BTN_TOUCH: c_int = 0x14a; +pub const BTN_STYLUS: c_int = 0x14b; +pub const BTN_STYLUS2: c_int = 0x14c; pub const BTN_TOOL_DOUBLETAP: c_int = 0x14d; pub const BTN_TOOL_TRIPLETAP: c_int = 0x14e; -pub const BTN_TOOL_QUADTAP: c_int = 0x14f; /* Four fingers on trackpad */ +pub const BTN_TOOL_QUADTAP: c_int = 0x14f; /* Four fingers on trackpad */ -pub const BTN_WHEEL: c_int = 0x150; +pub const BTN_WHEEL: c_int = 0x150; pub const BTN_GEAR_DOWN: c_int = 0x150; -pub const BTN_GEAR_UP: c_int = 0x151; +pub const BTN_GEAR_UP: c_int = 0x151; -pub const KEY_OK: c_int = 0x160; -pub const KEY_SELECT: c_int = 0x161; -pub const KEY_GOTO: c_int = 0x162; -pub const KEY_CLEAR: c_int = 0x163; -pub const KEY_POWER2: c_int = 0x164; -pub const KEY_OPTION: c_int = 0x165; -pub const KEY_INFO: c_int = 0x166; /* AL OEM Features/Tips/Tutorial */ -pub const KEY_TIME: c_int = 0x167; -pub const KEY_VENDOR: c_int = 0x168; -pub const KEY_ARCHIVE: c_int = 0x169; -pub const KEY_PROGRAM: c_int = 0x16a; /* Media Select Program Guide */ -pub const KEY_CHANNEL: c_int = 0x16b; -pub const KEY_FAVORITES: c_int = 0x16c; -pub const KEY_EPG: c_int = 0x16d; -pub const KEY_PVR: c_int = 0x16e; /* Media Select Home */ -pub const KEY_MHP: c_int = 0x16f; -pub const KEY_LANGUAGE: c_int = 0x170; -pub const KEY_TITLE: c_int = 0x171; -pub const KEY_SUBTITLE: c_int = 0x172; -pub const KEY_ANGLE: c_int = 0x173; -pub const KEY_ZOOM: c_int = 0x174; -pub const KEY_MODE: c_int = 0x175; -pub const KEY_KEYBOARD: c_int = 0x176; -pub const KEY_SCREEN: c_int = 0x177; -pub const KEY_PC: c_int = 0x178; /* Media Select Computer */ -pub const KEY_TV: c_int = 0x179; /* Media Select TV */ -pub const KEY_TV2: c_int = 0x17a; /* Media Select Cable */ -pub const KEY_VCR: c_int = 0x17b; /* Media Select VCR */ -pub const KEY_VCR2: c_int = 0x17c; /* VCR Plus */ -pub const KEY_SAT: c_int = 0x17d; /* Media Select Satellite */ -pub const KEY_SAT2: c_int = 0x17e; -pub const KEY_CD: c_int = 0x17f; /* Media Select CD */ -pub const KEY_TAPE: c_int = 0x180; /* Media Select Tape */ -pub const KEY_RADIO: c_int = 0x181; -pub const KEY_TUNER: c_int = 0x182; /* Media Select Tuner */ -pub const KEY_PLAYER: c_int = 0x183; -pub const KEY_TEXT: c_int = 0x184; -pub const KEY_DVD: c_int = 0x185; /* Media Select DVD */ -pub const KEY_AUX: c_int = 0x186; -pub const KEY_MP3: c_int = 0x187; -pub const KEY_AUDIO: c_int = 0x188; /* AL Audio Browser */ -pub const KEY_VIDEO: c_int = 0x189; /* AL Movie Browser */ -pub const KEY_DIRECTORY: c_int = 0x18a; -pub const KEY_LIST: c_int = 0x18b; -pub const KEY_MEMO: c_int = 0x18c; /* Media Select Messages */ -pub const KEY_CALENDAR: c_int = 0x18d; -pub const KEY_RED: c_int = 0x18e; -pub const KEY_GREEN: c_int = 0x18f; -pub const KEY_YELLOW: c_int = 0x190; -pub const KEY_BLUE: c_int = 0x191; -pub const KEY_CHANNELUP: c_int = 0x192; /* Channel Increment */ -pub const KEY_CHANNELDOWN: c_int = 0x193; /* Channel Decrement */ -pub const KEY_FIRST: c_int = 0x194; -pub const KEY_LAST: c_int = 0x195; /* Recall Last */ -pub const KEY_AB: c_int = 0x196; -pub const KEY_NEXT: c_int = 0x197; -pub const KEY_RESTART: c_int = 0x198; -pub const KEY_SLOW: c_int = 0x199; -pub const KEY_SHUFFLE: c_int = 0x19a; -pub const KEY_BREAK: c_int = 0x19b; -pub const KEY_PREVIOUS: c_int = 0x19c; -pub const KEY_DIGITS: c_int = 0x19d; -pub const KEY_TEEN: c_int = 0x19e; -pub const KEY_TWEN: c_int = 0x19f; -pub const KEY_VIDEOPHONE: c_int = 0x1a0; /* Media Select Video Phone */ -pub const KEY_GAMES: c_int = 0x1a1; /* Media Select Games */ -pub const KEY_ZOOMIN: c_int = 0x1a2; /* AC Zoom In */ -pub const KEY_ZOOMOUT: c_int = 0x1a3; /* AC Zoom Out */ -pub const KEY_ZOOMRESET: c_int = 0x1a4; /* AC Zoom */ -pub const KEY_WORDPROCESSOR: c_int = 0x1a5; /* AL Word Processor */ -pub const KEY_EDITOR: c_int = 0x1a6; /* AL Text Editor */ -pub const KEY_SPREADSHEET: c_int = 0x1a7; /* AL Spreadsheet */ -pub const KEY_GRAPHICSEDITOR: c_int = 0x1a8; /* AL Graphics Editor */ -pub const KEY_PRESENTATION: c_int = 0x1a9; /* AL Presentation App */ -pub const KEY_DATABASE: c_int = 0x1aa; /* AL Database App */ -pub const KEY_NEWS: c_int = 0x1ab; /* AL Newsreader */ -pub const KEY_VOICEMAIL: c_int = 0x1ac; /* AL Voicemail */ -pub const KEY_ADDRESSBOOK: c_int = 0x1ad; /* AL Contacts/Address Book */ -pub const KEY_MESSENGER: c_int = 0x1ae; /* AL Instant Messaging */ -pub const KEY_DISPLAYTOGGLE: c_int = 0x1af; /* Turn display : c_int = LCD on and off */ +pub const KEY_OK: c_int = 0x160; +pub const KEY_SELECT: c_int = 0x161; +pub const KEY_GOTO: c_int = 0x162; +pub const KEY_CLEAR: c_int = 0x163; +pub const KEY_POWER2: c_int = 0x164; +pub const KEY_OPTION: c_int = 0x165; +pub const KEY_INFO: c_int = 0x166; /* AL OEM Features/Tips/Tutorial */ +pub const KEY_TIME: c_int = 0x167; +pub const KEY_VENDOR: c_int = 0x168; +pub const KEY_ARCHIVE: c_int = 0x169; +pub const KEY_PROGRAM: c_int = 0x16a; /* Media Select Program Guide */ +pub const KEY_CHANNEL: c_int = 0x16b; +pub const KEY_FAVORITES: c_int = 0x16c; +pub const KEY_EPG: c_int = 0x16d; +pub const KEY_PVR: c_int = 0x16e; /* Media Select Home */ +pub const KEY_MHP: c_int = 0x16f; +pub const KEY_LANGUAGE: c_int = 0x170; +pub const KEY_TITLE: c_int = 0x171; +pub const KEY_SUBTITLE: c_int = 0x172; +pub const KEY_ANGLE: c_int = 0x173; +pub const KEY_ZOOM: c_int = 0x174; +pub const KEY_MODE: c_int = 0x175; +pub const KEY_KEYBOARD: c_int = 0x176; +pub const KEY_SCREEN: c_int = 0x177; +pub const KEY_PC: c_int = 0x178; /* Media Select Computer */ +pub const KEY_TV: c_int = 0x179; /* Media Select TV */ +pub const KEY_TV2: c_int = 0x17a; /* Media Select Cable */ +pub const KEY_VCR: c_int = 0x17b; /* Media Select VCR */ +pub const KEY_VCR2: c_int = 0x17c; /* VCR Plus */ +pub const KEY_SAT: c_int = 0x17d; /* Media Select Satellite */ +pub const KEY_SAT2: c_int = 0x17e; +pub const KEY_CD: c_int = 0x17f; /* Media Select CD */ +pub const KEY_TAPE: c_int = 0x180; /* Media Select Tape */ +pub const KEY_RADIO: c_int = 0x181; +pub const KEY_TUNER: c_int = 0x182; /* Media Select Tuner */ +pub const KEY_PLAYER: c_int = 0x183; +pub const KEY_TEXT: c_int = 0x184; +pub const KEY_DVD: c_int = 0x185; /* Media Select DVD */ +pub const KEY_AUX: c_int = 0x186; +pub const KEY_MP3: c_int = 0x187; +pub const KEY_AUDIO: c_int = 0x188; /* AL Audio Browser */ +pub const KEY_VIDEO: c_int = 0x189; /* AL Movie Browser */ +pub const KEY_DIRECTORY: c_int = 0x18a; +pub const KEY_LIST: c_int = 0x18b; +pub const KEY_MEMO: c_int = 0x18c; /* Media Select Messages */ +pub const KEY_CALENDAR: c_int = 0x18d; +pub const KEY_RED: c_int = 0x18e; +pub const KEY_GREEN: c_int = 0x18f; +pub const KEY_YELLOW: c_int = 0x190; +pub const KEY_BLUE: c_int = 0x191; +pub const KEY_CHANNELUP: c_int = 0x192; /* Channel Increment */ +pub const KEY_CHANNELDOWN: c_int = 0x193; /* Channel Decrement */ +pub const KEY_FIRST: c_int = 0x194; +pub const KEY_LAST: c_int = 0x195; /* Recall Last */ +pub const KEY_AB: c_int = 0x196; +pub const KEY_NEXT: c_int = 0x197; +pub const KEY_RESTART: c_int = 0x198; +pub const KEY_SLOW: c_int = 0x199; +pub const KEY_SHUFFLE: c_int = 0x19a; +pub const KEY_BREAK: c_int = 0x19b; +pub const KEY_PREVIOUS: c_int = 0x19c; +pub const KEY_DIGITS: c_int = 0x19d; +pub const KEY_TEEN: c_int = 0x19e; +pub const KEY_TWEN: c_int = 0x19f; +pub const KEY_VIDEOPHONE: c_int = 0x1a0; /* Media Select Video Phone */ +pub const KEY_GAMES: c_int = 0x1a1; /* Media Select Games */ +pub const KEY_ZOOMIN: c_int = 0x1a2; /* AC Zoom In */ +pub const KEY_ZOOMOUT: c_int = 0x1a3; /* AC Zoom Out */ +pub const KEY_ZOOMRESET: c_int = 0x1a4; /* AC Zoom */ +pub const KEY_WORDPROCESSOR: c_int = 0x1a5; /* AL Word Processor */ +pub const KEY_EDITOR: c_int = 0x1a6; /* AL Text Editor */ +pub const KEY_SPREADSHEET: c_int = 0x1a7; /* AL Spreadsheet */ +pub const KEY_GRAPHICSEDITOR: c_int = 0x1a8; /* AL Graphics Editor */ +pub const KEY_PRESENTATION: c_int = 0x1a9; /* AL Presentation App */ +pub const KEY_DATABASE: c_int = 0x1aa; /* AL Database App */ +pub const KEY_NEWS: c_int = 0x1ab; /* AL Newsreader */ +pub const KEY_VOICEMAIL: c_int = 0x1ac; /* AL Voicemail */ +pub const KEY_ADDRESSBOOK: c_int = 0x1ad; /* AL Contacts/Address Book */ +pub const KEY_MESSENGER: c_int = 0x1ae; /* AL Instant Messaging */ +pub const KEY_DISPLAYTOGGLE: c_int = 0x1af; /* Turn display : c_int = LCD on and off */ pub const KEY_BRIGHTNESS_TOGGLE: c_int = KEY_DISPLAYTOGGLE; -pub const KEY_SPELLCHECK: c_int = 0x1b0; /* AL Spell Check */ -pub const KEY_LOGOFF: c_int = 0x1b1; /* AL Logoff */ +pub const KEY_SPELLCHECK: c_int = 0x1b0; /* AL Spell Check */ +pub const KEY_LOGOFF: c_int = 0x1b1; /* AL Logoff */ pub const KEY_DOLLAR: c_int = 0x1b2; -pub const KEY_EURO: c_int = 0x1b3; +pub const KEY_EURO: c_int = 0x1b3; -pub const KEY_FRAMEBACK: c_int = 0x1b4; /* Consumer - transport controls */ -pub const KEY_FRAMEFORWARD: c_int = 0x1b5; -pub const KEY_CONTEXT_MENU: c_int = 0x1b6; /* GenDesc - system context menu */ -pub const KEY_MEDIA_REPEAT: c_int = 0x1b7; /* Consumer - transport control */ -pub const KEY_10CHANNELSUP: c_int = 0x1b8; /* 10 channels up : c_int = 10+ */ +pub const KEY_FRAMEBACK: c_int = 0x1b4; /* Consumer - transport controls */ +pub const KEY_FRAMEFORWARD: c_int = 0x1b5; +pub const KEY_CONTEXT_MENU: c_int = 0x1b6; /* GenDesc - system context menu */ +pub const KEY_MEDIA_REPEAT: c_int = 0x1b7; /* Consumer - transport control */ +pub const KEY_10CHANNELSUP: c_int = 0x1b8; /* 10 channels up : c_int = 10+ */ pub const KEY_10CHANNELSDOWN: c_int = 0x1b9; /* 10 channels down : c_int = 10- */ -pub const KEY_IMAGES: c_int = 0x1ba; /* AL Image Browser */ +pub const KEY_IMAGES: c_int = 0x1ba; /* AL Image Browser */ -pub const KEY_DEL_EOL: c_int = 0x1c0; -pub const KEY_DEL_EOS: c_int = 0x1c1; +pub const KEY_DEL_EOL: c_int = 0x1c0; +pub const KEY_DEL_EOS: c_int = 0x1c1; pub const KEY_INS_LINE: c_int = 0x1c2; pub const KEY_DEL_LINE: c_int = 0x1c3; -pub const KEY_FN: c_int = 0x1d0; +pub const KEY_FN: c_int = 0x1d0; pub const KEY_FN_ESC: c_int = 0x1d1; -pub const KEY_FN_F1: c_int = 0x1d2; -pub const KEY_FN_F2: c_int = 0x1d3; -pub const KEY_FN_F3: c_int = 0x1d4; -pub const KEY_FN_F4: c_int = 0x1d5; -pub const KEY_FN_F5: c_int = 0x1d6; -pub const KEY_FN_F6: c_int = 0x1d7; -pub const KEY_FN_F7: c_int = 0x1d8; -pub const KEY_FN_F8: c_int = 0x1d9; -pub const KEY_FN_F9: c_int = 0x1da; +pub const KEY_FN_F1: c_int = 0x1d2; +pub const KEY_FN_F2: c_int = 0x1d3; +pub const KEY_FN_F3: c_int = 0x1d4; +pub const KEY_FN_F4: c_int = 0x1d5; +pub const KEY_FN_F5: c_int = 0x1d6; +pub const KEY_FN_F6: c_int = 0x1d7; +pub const KEY_FN_F7: c_int = 0x1d8; +pub const KEY_FN_F8: c_int = 0x1d9; +pub const KEY_FN_F9: c_int = 0x1da; pub const KEY_FN_F10: c_int = 0x1db; pub const KEY_FN_F11: c_int = 0x1dc; pub const KEY_FN_F12: c_int = 0x1dd; -pub const KEY_FN_1: c_int = 0x1de; -pub const KEY_FN_2: c_int = 0x1df; -pub const KEY_FN_D: c_int = 0x1e0; -pub const KEY_FN_E: c_int = 0x1e1; -pub const KEY_FN_F: c_int = 0x1e2; -pub const KEY_FN_S: c_int = 0x1e3; -pub const KEY_FN_B: c_int = 0x1e4; +pub const KEY_FN_1: c_int = 0x1de; +pub const KEY_FN_2: c_int = 0x1df; +pub const KEY_FN_D: c_int = 0x1e0; +pub const KEY_FN_E: c_int = 0x1e1; +pub const KEY_FN_F: c_int = 0x1e2; +pub const KEY_FN_S: c_int = 0x1e3; +pub const KEY_FN_B: c_int = 0x1e4; -pub const KEY_BRL_DOT1: c_int = 0x1f1; -pub const KEY_BRL_DOT2: c_int = 0x1f2; -pub const KEY_BRL_DOT3: c_int = 0x1f3; -pub const KEY_BRL_DOT4: c_int = 0x1f4; -pub const KEY_BRL_DOT5: c_int = 0x1f5; -pub const KEY_BRL_DOT6: c_int = 0x1f6; -pub const KEY_BRL_DOT7: c_int = 0x1f7; -pub const KEY_BRL_DOT8: c_int = 0x1f8; -pub const KEY_BRL_DOT9: c_int = 0x1f9; +pub const KEY_BRL_DOT1: c_int = 0x1f1; +pub const KEY_BRL_DOT2: c_int = 0x1f2; +pub const KEY_BRL_DOT3: c_int = 0x1f3; +pub const KEY_BRL_DOT4: c_int = 0x1f4; +pub const KEY_BRL_DOT5: c_int = 0x1f5; +pub const KEY_BRL_DOT6: c_int = 0x1f6; +pub const KEY_BRL_DOT7: c_int = 0x1f7; +pub const KEY_BRL_DOT8: c_int = 0x1f8; +pub const KEY_BRL_DOT9: c_int = 0x1f9; pub const KEY_BRL_DOT10: c_int = 0x1fa; -pub const KEY_NUMERIC_0: c_int = 0x200; /* used by phones, remote controls, */ -pub const KEY_NUMERIC_1: c_int = 0x201; /* and other keypads */ -pub const KEY_NUMERIC_2: c_int = 0x202; -pub const KEY_NUMERIC_3: c_int = 0x203; -pub const KEY_NUMERIC_4: c_int = 0x204; -pub const KEY_NUMERIC_5: c_int = 0x205; -pub const KEY_NUMERIC_6: c_int = 0x206; -pub const KEY_NUMERIC_7: c_int = 0x207; -pub const KEY_NUMERIC_8: c_int = 0x208; -pub const KEY_NUMERIC_9: c_int = 0x209; -pub const KEY_NUMERIC_STAR: c_int = 0x20a; +pub const KEY_NUMERIC_0: c_int = 0x200; /* used by phones, remote controls, */ +pub const KEY_NUMERIC_1: c_int = 0x201; /* and other keypads */ +pub const KEY_NUMERIC_2: c_int = 0x202; +pub const KEY_NUMERIC_3: c_int = 0x203; +pub const KEY_NUMERIC_4: c_int = 0x204; +pub const KEY_NUMERIC_5: c_int = 0x205; +pub const KEY_NUMERIC_6: c_int = 0x206; +pub const KEY_NUMERIC_7: c_int = 0x207; +pub const KEY_NUMERIC_8: c_int = 0x208; +pub const KEY_NUMERIC_9: c_int = 0x209; +pub const KEY_NUMERIC_STAR: c_int = 0x20a; pub const KEY_NUMERIC_POUND: c_int = 0x20b; -pub const KEY_NUMERIC_A: c_int = 0x20c; /* Phone key A - HUT Telephony 0xb9 */ -pub const KEY_NUMERIC_B: c_int = 0x20d; -pub const KEY_NUMERIC_C: c_int = 0x20e; -pub const KEY_NUMERIC_D: c_int = 0x20f; +pub const KEY_NUMERIC_A: c_int = 0x20c; /* Phone key A - HUT Telephony 0xb9 */ +pub const KEY_NUMERIC_B: c_int = 0x20d; +pub const KEY_NUMERIC_C: c_int = 0x20e; +pub const KEY_NUMERIC_D: c_int = 0x20f; pub const KEY_CAMERA_FOCUS: c_int = 0x210; -pub const KEY_WPS_BUTTON: c_int = 0x211; /* WiFi Protected Setup key */ +pub const KEY_WPS_BUTTON: c_int = 0x211; /* WiFi Protected Setup key */ pub const KEY_TOUCHPAD_TOGGLE: c_int = 0x212; /* Request switch touchpad on or off */ -pub const KEY_TOUCHPAD_ON: c_int = 0x213; -pub const KEY_TOUCHPAD_OFF: c_int = 0x214; +pub const KEY_TOUCHPAD_ON: c_int = 0x213; +pub const KEY_TOUCHPAD_OFF: c_int = 0x214; -pub const KEY_CAMERA_ZOOMIN: c_int = 0x215; +pub const KEY_CAMERA_ZOOMIN: c_int = 0x215; pub const KEY_CAMERA_ZOOMOUT: c_int = 0x216; -pub const KEY_CAMERA_UP: c_int = 0x217; -pub const KEY_CAMERA_DOWN: c_int = 0x218; -pub const KEY_CAMERA_LEFT: c_int = 0x219; -pub const KEY_CAMERA_RIGHT: c_int = 0x21a; +pub const KEY_CAMERA_UP: c_int = 0x217; +pub const KEY_CAMERA_DOWN: c_int = 0x218; +pub const KEY_CAMERA_LEFT: c_int = 0x219; +pub const KEY_CAMERA_RIGHT: c_int = 0x21a; -pub const KEY_ATTENDANT_ON: c_int = 0x21b; -pub const KEY_ATTENDANT_OFF: c_int = 0x21c; +pub const KEY_ATTENDANT_ON: c_int = 0x21b; +pub const KEY_ATTENDANT_OFF: c_int = 0x21c; pub const KEY_ATTENDANT_TOGGLE: c_int = 0x21d; /* Attendant call on or off */ -pub const KEY_LIGHTS_TOGGLE: c_int = 0x21e; /* Reading light on or off */ +pub const KEY_LIGHTS_TOGGLE: c_int = 0x21e; /* Reading light on or off */ -pub const BTN_DPAD_UP: c_int = 0x220; -pub const BTN_DPAD_DOWN: c_int = 0x221; -pub const BTN_DPAD_LEFT: c_int = 0x222; +pub const BTN_DPAD_UP: c_int = 0x220; +pub const BTN_DPAD_DOWN: c_int = 0x221; +pub const BTN_DPAD_LEFT: c_int = 0x222; pub const BTN_DPAD_RIGHT: c_int = 0x223; pub const KEY_ALS_TOGGLE: c_int = 0x230; /* Ambient light sensor */ -pub const KEY_BUTTONCONFIG: c_int = 0x240; /* AL Button Configuration */ -pub const KEY_TASKMANAGER: c_int = 0x241; /* AL Task/Project Manager */ -pub const KEY_JOURNAL: c_int = 0x242; /* AL Log/Journal/Timecard */ -pub const KEY_CONTROLPANEL: c_int = 0x243; /* AL Control Panel */ -pub const KEY_APPSELECT: c_int = 0x244; /* AL Select Task/Application */ -pub const KEY_SCREENSAVER: c_int = 0x245; /* AL Screen Saver */ -pub const KEY_VOICECOMMAND: c_int = 0x246; /* Listening Voice Command */ +pub const KEY_BUTTONCONFIG: c_int = 0x240; /* AL Button Configuration */ +pub const KEY_TASKMANAGER: c_int = 0x241; /* AL Task/Project Manager */ +pub const KEY_JOURNAL: c_int = 0x242; /* AL Log/Journal/Timecard */ +pub const KEY_CONTROLPANEL: c_int = 0x243; /* AL Control Panel */ +pub const KEY_APPSELECT: c_int = 0x244; /* AL Select Task/Application */ +pub const KEY_SCREENSAVER: c_int = 0x245; /* AL Screen Saver */ +pub const KEY_VOICECOMMAND: c_int = 0x246; /* Listening Voice Command */ pub const KEY_BRIGHTNESS_MIN: c_int = 0x250; /* Set Brightness to Minimum */ pub const KEY_BRIGHTNESS_MAX: c_int = 0x251; /* Set Brightness to Maximum */ -pub const KEY_KBDINPUTASSIST_PREV: c_int = 0x260; -pub const KEY_KBDINPUTASSIST_NEXT: c_int = 0x261; +pub const KEY_KBDINPUTASSIST_PREV: c_int = 0x260; +pub const KEY_KBDINPUTASSIST_NEXT: c_int = 0x261; pub const KEY_KBDINPUTASSIST_PREVGROUP: c_int = 0x262; pub const KEY_KBDINPUTASSIST_NEXTGROUP: c_int = 0x263; -pub const KEY_KBDINPUTASSIST_ACCEPT: c_int = 0x264; -pub const KEY_KBDINPUTASSIST_CANCEL: c_int = 0x265; +pub const KEY_KBDINPUTASSIST_ACCEPT: c_int = 0x264; +pub const KEY_KBDINPUTASSIST_CANCEL: c_int = 0x265; -pub const BTN_TRIGGER_HAPPY: c_int = 0x2c0; -pub const BTN_TRIGGER_HAPPY1: c_int = 0x2c0; -pub const BTN_TRIGGER_HAPPY2: c_int = 0x2c1; -pub const BTN_TRIGGER_HAPPY3: c_int = 0x2c2; -pub const BTN_TRIGGER_HAPPY4: c_int = 0x2c3; -pub const BTN_TRIGGER_HAPPY5: c_int = 0x2c4; -pub const BTN_TRIGGER_HAPPY6: c_int = 0x2c5; -pub const BTN_TRIGGER_HAPPY7: c_int = 0x2c6; -pub const BTN_TRIGGER_HAPPY8: c_int = 0x2c7; -pub const BTN_TRIGGER_HAPPY9: c_int = 0x2c8; +pub const BTN_TRIGGER_HAPPY: c_int = 0x2c0; +pub const BTN_TRIGGER_HAPPY1: c_int = 0x2c0; +pub const BTN_TRIGGER_HAPPY2: c_int = 0x2c1; +pub const BTN_TRIGGER_HAPPY3: c_int = 0x2c2; +pub const BTN_TRIGGER_HAPPY4: c_int = 0x2c3; +pub const BTN_TRIGGER_HAPPY5: c_int = 0x2c4; +pub const BTN_TRIGGER_HAPPY6: c_int = 0x2c5; +pub const BTN_TRIGGER_HAPPY7: c_int = 0x2c6; +pub const BTN_TRIGGER_HAPPY8: c_int = 0x2c7; +pub const BTN_TRIGGER_HAPPY9: c_int = 0x2c8; pub const BTN_TRIGGER_HAPPY10: c_int = 0x2c9; pub const BTN_TRIGGER_HAPPY11: c_int = 0x2ca; pub const BTN_TRIGGER_HAPPY12: c_int = 0x2cb; @@ -633,75 +633,74 @@ pub const BTN_TRIGGER_HAPPY40: c_int = 0x2e7; /* We avoid low common keys in module aliases so they don't get huge. */ pub const KEY_MIN_INTERESTING: c_int = KEY_MUTE; -pub const KEY_MAX: c_int = 0x2ff; -pub const KEY_CNT: c_int = KEY_MAX + 1; +pub const KEY_MAX: c_int = 0x2ff; +pub const KEY_CNT: c_int = KEY_MAX + 1; /* * Relative axes */ -pub const REL_X: c_int = 0x00; -pub const REL_Y: c_int = 0x01; -pub const REL_Z: c_int = 0x02; -pub const REL_RX: c_int = 0x03; -pub const REL_RY: c_int = 0x04; -pub const REL_RZ: c_int = 0x05; +pub const REL_X: c_int = 0x00; +pub const REL_Y: c_int = 0x01; +pub const REL_Z: c_int = 0x02; +pub const REL_RX: c_int = 0x03; +pub const REL_RY: c_int = 0x04; +pub const REL_RZ: c_int = 0x05; pub const REL_HWHEEL: c_int = 0x06; -pub const REL_DIAL: c_int = 0x07; -pub const REL_WHEEL: c_int = 0x08; -pub const REL_MISC: c_int = 0x09; -pub const REL_MAX: c_int = 0x0f; -pub const REL_CNT: c_int = REL_MAX + 1; +pub const REL_DIAL: c_int = 0x07; +pub const REL_WHEEL: c_int = 0x08; +pub const REL_MISC: c_int = 0x09; +pub const REL_MAX: c_int = 0x0f; +pub const REL_CNT: c_int = REL_MAX + 1; /* * Absolute axes */ -pub const ABS_X: c_int = 0x00; -pub const ABS_Y: c_int = 0x01; -pub const ABS_Z: c_int = 0x02; -pub const ABS_RX: c_int = 0x03; -pub const ABS_RY: c_int = 0x04; -pub const ABS_RZ: c_int = 0x05; -pub const ABS_THROTTLE: c_int = 0x06; -pub const ABS_RUDDER: c_int = 0x07; -pub const ABS_WHEEL: c_int = 0x08; -pub const ABS_GAS: c_int = 0x09; -pub const ABS_BRAKE: c_int = 0x0a; -pub const ABS_HAT0X: c_int = 0x10; -pub const ABS_HAT0Y: c_int = 0x11; -pub const ABS_HAT1X: c_int = 0x12; -pub const ABS_HAT1Y: c_int = 0x13; -pub const ABS_HAT2X: c_int = 0x14; -pub const ABS_HAT2Y: c_int = 0x15; -pub const ABS_HAT3X: c_int = 0x16; -pub const ABS_HAT3Y: c_int = 0x17; -pub const ABS_PRESSURE: c_int = 0x18; -pub const ABS_DISTANCE: c_int = 0x19; -pub const ABS_TILT_X: c_int = 0x1a; -pub const ABS_TILT_Y: c_int = 0x1b; +pub const ABS_X: c_int = 0x00; +pub const ABS_Y: c_int = 0x01; +pub const ABS_Z: c_int = 0x02; +pub const ABS_RX: c_int = 0x03; +pub const ABS_RY: c_int = 0x04; +pub const ABS_RZ: c_int = 0x05; +pub const ABS_THROTTLE: c_int = 0x06; +pub const ABS_RUDDER: c_int = 0x07; +pub const ABS_WHEEL: c_int = 0x08; +pub const ABS_GAS: c_int = 0x09; +pub const ABS_BRAKE: c_int = 0x0a; +pub const ABS_HAT0X: c_int = 0x10; +pub const ABS_HAT0Y: c_int = 0x11; +pub const ABS_HAT1X: c_int = 0x12; +pub const ABS_HAT1Y: c_int = 0x13; +pub const ABS_HAT2X: c_int = 0x14; +pub const ABS_HAT2Y: c_int = 0x15; +pub const ABS_HAT3X: c_int = 0x16; +pub const ABS_HAT3Y: c_int = 0x17; +pub const ABS_PRESSURE: c_int = 0x18; +pub const ABS_DISTANCE: c_int = 0x19; +pub const ABS_TILT_X: c_int = 0x1a; +pub const ABS_TILT_Y: c_int = 0x1b; pub const ABS_TOOL_WIDTH: c_int = 0x1c; pub const ABS_VOLUME: c_int = 0x20; pub const ABS_MISC: c_int = 0x28; -pub const ABS_MT_SLOT: c_int = 0x2f; /* MT slot being modified */ +pub const ABS_MT_SLOT: c_int = 0x2f; /* MT slot being modified */ pub const ABS_MT_TOUCH_MAJOR: c_int = 0x30; /* Major axis of touching ellipse */ pub const ABS_MT_TOUCH_MINOR: c_int = 0x31; /* Minor axis : c_int = omit if circular */ pub const ABS_MT_WIDTH_MAJOR: c_int = 0x32; /* Major axis of approaching ellipse */ pub const ABS_MT_WIDTH_MINOR: c_int = 0x33; /* Minor axis : c_int = omit if circular */ pub const ABS_MT_ORIENTATION: c_int = 0x34; /* Ellipse orientation */ -pub const ABS_MT_POSITION_X: c_int = 0x35; /* Center X touch position */ -pub const ABS_MT_POSITION_Y: c_int = 0x36; /* Center Y touch position */ -pub const ABS_MT_TOOL_TYPE: c_int = 0x37; /* Type of touching device */ -pub const ABS_MT_BLOB_ID: c_int = 0x38; /* Group a set of packets as a blob */ +pub const ABS_MT_POSITION_X: c_int = 0x35; /* Center X touch position */ +pub const ABS_MT_POSITION_Y: c_int = 0x36; /* Center Y touch position */ +pub const ABS_MT_TOOL_TYPE: c_int = 0x37; /* Type of touching device */ +pub const ABS_MT_BLOB_ID: c_int = 0x38; /* Group a set of packets as a blob */ pub const ABS_MT_TRACKING_ID: c_int = 0x39; /* Unique ID of initiated contact */ -pub const ABS_MT_PRESSURE: c_int = 0x3a; /* Pressure on contact area */ -pub const ABS_MT_DISTANCE: c_int = 0x3b; /* Contact hover distance */ -pub const ABS_MT_TOOL_X: c_int = 0x3c; /* Center X tool position */ -pub const ABS_MT_TOOL_Y: c_int = 0x3d; /* Center Y tool position */ - +pub const ABS_MT_PRESSURE: c_int = 0x3a; /* Pressure on contact area */ +pub const ABS_MT_DISTANCE: c_int = 0x3b; /* Contact hover distance */ +pub const ABS_MT_TOOL_X: c_int = 0x3c; /* Center X tool position */ +pub const ABS_MT_TOOL_Y: c_int = 0x3d; /* Center Y tool position */ pub const ABS_MAX: c_int = 0x3f; pub const ABS_CNT: c_int = ABS_MAX + 1; @@ -710,71 +709,71 @@ pub const ABS_CNT: c_int = ABS_MAX + 1; * Switch events */ -pub const SW_LID: c_int = 0x00; /* set = lid shut */ -pub const SW_TABLET_MODE: c_int = 0x01; /* set = tablet mode */ -pub const SW_HEADPHONE_INSERT: c_int = 0x02; /* set = inserted */ -pub const SW_RFKILL_ALL: c_int = 0x03; /* rfkill master switch, type "any" set = radio enabled */ -pub const SW_RADIO: c_int = SW_RFKILL_ALL; /* deprecated */ -pub const SW_MICROPHONE_INSERT: c_int = 0x04; /* set = inserted */ -pub const SW_DOCK: c_int = 0x05; /* set = plugged into dock */ -pub const SW_LINEOUT_INSERT: c_int = 0x06; /* set = inserted */ -pub const SW_JACK_PHYSICAL_INSERT: c_int = 0x07; /* set = mechanical switch set */ -pub const SW_VIDEOOUT_INSERT: c_int = 0x08; /* set = inserted */ -pub const SW_CAMERA_LENS_COVER: c_int = 0x09; /* set = lens covered */ -pub const SW_KEYPAD_SLIDE: c_int = 0x0a; /* set = keypad slide out */ -pub const SW_FRONT_PROXIMITY: c_int = 0x0b; /* set = front proximity sensor active */ -pub const SW_ROTATE_LOCK: c_int = 0x0c; /* set = rotate locked/disabled */ -pub const SW_LINEIN_INSERT: c_int = 0x0d; /* set = inserted */ -pub const SW_MUTE_DEVICE: c_int = 0x0e; /* set = device disabled */ -pub const SW_MAX: c_int = 0x0f; -pub const SW_CNT: c_int = SW_MAX + 1; +pub const SW_LID: c_int = 0x00; /* set = lid shut */ +pub const SW_TABLET_MODE: c_int = 0x01; /* set = tablet mode */ +pub const SW_HEADPHONE_INSERT: c_int = 0x02; /* set = inserted */ +pub const SW_RFKILL_ALL: c_int = 0x03; /* rfkill master switch, type "any" set = radio enabled */ +pub const SW_RADIO: c_int = SW_RFKILL_ALL; /* deprecated */ +pub const SW_MICROPHONE_INSERT: c_int = 0x04; /* set = inserted */ +pub const SW_DOCK: c_int = 0x05; /* set = plugged into dock */ +pub const SW_LINEOUT_INSERT: c_int = 0x06; /* set = inserted */ +pub const SW_JACK_PHYSICAL_INSERT: c_int = 0x07; /* set = mechanical switch set */ +pub const SW_VIDEOOUT_INSERT: c_int = 0x08; /* set = inserted */ +pub const SW_CAMERA_LENS_COVER: c_int = 0x09; /* set = lens covered */ +pub const SW_KEYPAD_SLIDE: c_int = 0x0a; /* set = keypad slide out */ +pub const SW_FRONT_PROXIMITY: c_int = 0x0b; /* set = front proximity sensor active */ +pub const SW_ROTATE_LOCK: c_int = 0x0c; /* set = rotate locked/disabled */ +pub const SW_LINEIN_INSERT: c_int = 0x0d; /* set = inserted */ +pub const SW_MUTE_DEVICE: c_int = 0x0e; /* set = device disabled */ +pub const SW_MAX: c_int = 0x0f; +pub const SW_CNT: c_int = SW_MAX + 1; /* * Misc events */ -pub const MSC_SERIAL: c_int = 0x00; -pub const MSC_PULSELED: c_int = 0x01; -pub const MSC_GESTURE: c_int = 0x02; -pub const MSC_RAW: c_int = 0x03; -pub const MSC_SCAN: c_int = 0x04; +pub const MSC_SERIAL: c_int = 0x00; +pub const MSC_PULSELED: c_int = 0x01; +pub const MSC_GESTURE: c_int = 0x02; +pub const MSC_RAW: c_int = 0x03; +pub const MSC_SCAN: c_int = 0x04; pub const MSC_TIMESTAMP: c_int = 0x05; -pub const MSC_MAX: c_int = 0x07; -pub const MSC_CNT: c_int = MSC_MAX + 1; +pub const MSC_MAX: c_int = 0x07; +pub const MSC_CNT: c_int = MSC_MAX + 1; /* * LEDs */ -pub const LED_NUML: c_int = 0x00; -pub const LED_CAPSL: c_int = 0x01; -pub const LED_SCROLLL: c_int = 0x02; -pub const LED_COMPOSE: c_int = 0x03; -pub const LED_KANA: c_int = 0x04; -pub const LED_SLEEP: c_int = 0x05; -pub const LED_SUSPEND: c_int = 0x06; -pub const LED_MUTE: c_int = 0x07; -pub const LED_MISC: c_int = 0x08; -pub const LED_MAIL: c_int = 0x09; +pub const LED_NUML: c_int = 0x00; +pub const LED_CAPSL: c_int = 0x01; +pub const LED_SCROLLL: c_int = 0x02; +pub const LED_COMPOSE: c_int = 0x03; +pub const LED_KANA: c_int = 0x04; +pub const LED_SLEEP: c_int = 0x05; +pub const LED_SUSPEND: c_int = 0x06; +pub const LED_MUTE: c_int = 0x07; +pub const LED_MISC: c_int = 0x08; +pub const LED_MAIL: c_int = 0x09; pub const LED_CHARGING: c_int = 0x0a; -pub const LED_MAX: c_int = 0x0f; -pub const LED_CNT: c_int = LED_MAX + 1; +pub const LED_MAX: c_int = 0x0f; +pub const LED_CNT: c_int = LED_MAX + 1; /* * Autorepeat values */ -pub const REP_DELAY: c_int = 0x00; +pub const REP_DELAY: c_int = 0x00; pub const REP_PERIOD: c_int = 0x01; -pub const REP_MAX: c_int = 0x01; -pub const REP_CNT: c_int = REP_MAX + 1; +pub const REP_MAX: c_int = 0x01; +pub const REP_CNT: c_int = REP_MAX + 1; /* * Sounds */ pub const SND_CLICK: c_int = 0x00; -pub const SND_BELL: c_int = 0x01; -pub const SND_TONE: c_int = 0x02; -pub const SND_MAX: c_int = 0x07; -pub const SND_CNT: c_int = SND_MAX + 1; +pub const SND_BELL: c_int = 0x01; +pub const SND_TONE: c_int = 0x02; +pub const SND_MAX: c_int = 0x07; +pub const SND_CNT: c_int = SND_MAX + 1; diff --git a/src/linux/device/device.rs b/src/linux/device/device.rs index bff182b..3972d99 100644 --- a/src/linux/device/device.rs +++ b/src/linux/device/device.rs @@ -1,7 +1,7 @@ -use std::{mem, ptr, slice}; -use libc::{timeval, gettimeofday, input_event, c_int}; -use nix::{unistd, ioctl_none}; use crate::Result; +use libc::{c_int, gettimeofday, input_event, timeval}; +use nix::{ioctl_none, unistd}; +use std::{mem, ptr, slice}; use crate::linux::device::codes::*; @@ -9,80 +9,81 @@ ioctl_none!(ui_dev_destroy, b'U', 2); /// The virtual device. pub struct Device { - fd: c_int, + fd: c_int, } impl Device { - /// Wrap a file descriptor in a `Device`. - pub fn new(fd: c_int) -> Self { - Device { - fd: fd - } - } + /// Wrap a file descriptor in a `Device`. + pub fn new(fd: c_int) -> Self { + Device { fd: fd } + } - #[doc(hidden)] - pub fn write(&self, kind: c_int, code: c_int, value: c_int) -> Result<()> { - let mut event = input_event { - time: timeval { tv_sec: 0, tv_usec: 0 }, - type_: kind as u16, - code: code as u16, - value: value as i32, - }; + #[doc(hidden)] + pub fn write(&self, kind: c_int, code: c_int, value: c_int) -> Result<()> { + let mut event = input_event { + time: timeval { + tv_sec: 0, + tv_usec: 0, + }, + type_: kind as u16, + code: code as u16, + value: value as i32, + }; - self.write_event(&mut event) - } + self.write_event(&mut event) + } - #[doc(hidden)] - pub fn write_event(&self, event: &mut input_event) -> Result<()> { - unsafe { - gettimeofday(&mut event.time, ptr::null_mut()); + #[doc(hidden)] + pub fn write_event(&self, event: &mut input_event) -> Result<()> { + unsafe { + gettimeofday(&mut event.time, ptr::null_mut()); - let ptr = event as *const _ as *const u8; - let size = mem::size_of_val(event); + let ptr = event as *const _ as *const u8; + let size = mem::size_of_val(event); - unistd::write(self.fd, slice::from_raw_parts(ptr, size))?; - } + unistd::write(self.fd, slice::from_raw_parts(ptr, size))?; + } - Ok(()) - } + Ok(()) + } - /// Synchronize the device. - pub fn synchronize(&self) -> Result<()> { - self.write(EV_SYN, SYN_REPORT, 0) - } + /// Synchronize the device. + pub fn synchronize(&self) -> Result<()> { + self.write(EV_SYN, SYN_REPORT, 0) + } - /// Send an event. - pub fn send(&self, kind: c_int, code: c_int, value: i32) -> Result<()> { - self.write(kind, code, value) - } + /// Send an event. + pub fn send(&self, kind: c_int, code: c_int, value: i32) -> Result<()> { + self.write(kind, code, value) + } - /// Send a press event. - pub fn press(&self, kind: c_int, code: c_int) -> Result<()> { - self.write(kind, code, 1) - } + /// Send a press event. + pub fn press(&self, kind: c_int, code: c_int) -> Result<()> { + self.write(kind, code, 1) + } - /// Send a release event. - pub fn release(&self, kind: c_int, code: c_int) -> Result<()> { - self.write(kind, code, 0) - } + /// Send a release event. + pub fn release(&self, kind: c_int, code: c_int) -> Result<()> { + self.write(kind, code, 0) + } - /// Send a press and release event. - pub fn click(&self, kind: c_int, code: c_int) -> Result<()> { - self.press(kind, code)?; - self.release(kind, code) - } + /// Send a press and release event. + pub fn click(&self, kind: c_int, code: c_int) -> Result<()> { + self.press(kind, code)?; + self.release(kind, code) + } - /// Send a relative or absolute positioning event. - pub fn position(&self, kind: c_int, code: c_int, value: i32) -> Result<()> { - self.write(kind, code, value) - } + /// Send a relative or absolute positioning event. + pub fn position(&self, kind: c_int, code: c_int, value: i32) -> Result<()> { + self.write(kind, code, value) + } } impl Drop for Device { - fn drop(&mut self) { - unsafe { - // ignore error here so as to not panic in a drop - ui_dev_destroy(self.fd).ok(); - } - } + fn drop(&mut self) { + unsafe { + // ignore error here so as to not panic in a drop + ui_dev_destroy(self.fd).ok(); + } + } } diff --git a/src/linux/device/input_device.rs b/src/linux/device/input_device.rs index 77ecbec..34763ea 100644 --- a/src/linux/device/input_device.rs +++ b/src/linux/device/input_device.rs @@ -1,15 +1,14 @@ -use std::mem; -use std::fs::File; -use std::io::Read; -use std::os::unix::io::AsRawFd; -use libc::{input_event, c_int}; -use nix::{ioctl_write_ptr, ioctl_read_buf}; +use libc::{c_int, input_event}; +use nix::{ioctl_read_buf, ioctl_write_ptr}; +use std::{fs::File, io::Read, mem, os::unix::io::AsRawFd}; #[cfg(feature = "epoll_inotify")] use std::os::unix::prelude::RawFd; -use crate::{Error,Result}; -use crate::linux::{EV_KEY, KEY_MAX, NAME, KEY_W, KEY_A, KEY_S, KEY_D, BTN_LEFT}; +use crate::{ + linux::{BTN_LEFT, EV_KEY, KEY_A, KEY_D, KEY_MAX, KEY_S, KEY_W, NAME}, + Error, Result, +}; ioctl_write_ptr!(eviocgrab, b'E', 0x90, c_int); ioctl_read_buf!(eviocgname, b'E', 0x06, u8); @@ -34,7 +33,7 @@ impl InputDevice { epoll_fd: None, }) } - + pub fn new_input_event_buf() -> [u8; SIZE_OF_INPUT_EVENT] { [0u8; SIZE_OF_INPUT_EVENT] } @@ -55,7 +54,7 @@ impl InputDevice { if !self.device_file.metadata()?.file_type().is_char_device() { return Err(Error::NotAKeyboard); } - + let raw_fd = self.device_file.as_raw_fd(); // does it support EV_KEY @@ -73,16 +72,19 @@ impl InputDevice { unsafe { eviocgbit_ev_key(raw_fd, &mut key_bits)?; }; - let key_unsupported = |key : c_int| (key_bits[key as usize / 8] & (1 << (key % 8))) == 0; - if key_unsupported(KEY_W) || key_unsupported(KEY_A) || key_unsupported(KEY_S) || key_unsupported(KEY_D) || !key_unsupported(BTN_LEFT) { + let key_unsupported = |key: c_int| (key_bits[key as usize / 8] & (1 << (key % 8))) == 0; + if key_unsupported(KEY_W) + || key_unsupported(KEY_A) + || key_unsupported(KEY_S) + || key_unsupported(KEY_D) + || !key_unsupported(BTN_LEFT) + { return Err(Error::NotAKeyboard); } // is it another running copy of rusty-keys ? let mut name = [0u8; NAME.len()]; - unsafe { - eviocgname(raw_fd, &mut name)? - }; + unsafe { eviocgname(raw_fd, &mut name)? }; // exclude anything starting with "Yubico" also if NAME.as_bytes() == &name || "Yubico".as_bytes() == &name[0..6] { return Err(Error::NotAKeyboard); @@ -107,10 +109,10 @@ impl InputDevice { } Ok(()) } - + #[cfg(feature = "epoll_inotify")] pub fn epoll_add(mut self, epoll_fd: RawFd, data: u64) -> Result { - use nix::fcntl::{OFlag, fcntl, FcntlArg}; + use nix::fcntl::{fcntl, FcntlArg, OFlag}; if None != self.epoll_fd { return Err(Error::EpollAlreadyAdded); @@ -123,7 +125,12 @@ impl InputDevice { fcntl(raw_fd, FcntlArg::F_SETFL(flags | OFlag::O_NONBLOCK))?; let epoll_event = epoll::Event::new(epoll::Events::EPOLLIN | epoll::Events::EPOLLET, data); - epoll::ctl(epoll_fd, epoll::ControlOptions::EPOLL_CTL_ADD, raw_fd, epoll_event)?; + epoll::ctl( + epoll_fd, + epoll::ControlOptions::EPOLL_CTL_ADD, + raw_fd, + epoll_event, + )?; self.epoll_fd = Some(epoll_fd); Ok(self) } @@ -134,7 +141,12 @@ impl InputDevice { // set this to None first, if we end up returning an Err early, we can't do anything else anyway... self.epoll_fd = None; let empty_event = epoll::Event::new(epoll::Events::empty(), 0); - epoll::ctl(epoll_fd, epoll::ControlOptions::EPOLL_CTL_DEL, self.device_file.as_raw_fd(), empty_event)?; + epoll::ctl( + epoll_fd, + epoll::ControlOptions::EPOLL_CTL_DEL, + self.device_file.as_raw_fd(), + empty_event, + )?; } Ok(self) } diff --git a/src/linux/mod.rs b/src/linux/mod.rs index 02f8abc..213265c 100644 --- a/src/linux/mod.rs +++ b/src/linux/mod.rs @@ -1,15 +1,12 @@ - use crate::*; use crate::linux::device::codes::*; pub mod device; -pub use device::{Device,InputDevice, Builder}; +pub use device::{Builder, Device, InputDevice}; use libc::input_event; -use std::process::exit; -use std::env; -use std::collections::HashMap; +use std::{collections::HashMap, env, process::exit}; #[cfg(feature = "epoll_inotify")] const INPUT_FOLDER: &str = "/dev/input/"; @@ -48,7 +45,12 @@ impl Keyboard for Device { Keyboard::send(self, event) } - fn send_mod_code_value(&self, code: u16, up_not_down: bool, event: &mut input_event) -> Result<()> { + fn send_mod_code_value( + &self, + code: u16, + up_not_down: bool, + event: &mut input_event, + ) -> Result<()> { event.code = code; let value = event.value; if up_not_down { @@ -86,12 +88,15 @@ impl Keyboard for Device { #[derive(Debug)] struct Config { device_files: Vec, - config_file: String + config_file: String, } impl Config { fn new(device_files: Vec, config_file: String) -> Self { - Config { device_files: device_files, config_file: config_file } + Config { + device_files: device_files, + config_file: config_file, + } } } @@ -130,91 +135,120 @@ pub fn main_res() -> Result<()> { panic!("without epoll_inotify feature, only exactly 1 device is supported"); #[cfg(feature = "epoll_inotify")] - { - use inotify::{Inotify, WatchMask}; + { + use inotify::{Inotify, WatchMask}; - let epoll_fd = epoll::create(true)?; - const INOTIFY_DATA: u64 = u64::max_value(); + let epoll_fd = epoll::create(true)?; + const INOTIFY_DATA: u64 = u64::max_value(); - let (device_files, mut inotify) = if config.device_files.len() > 0 { - // we operate on exactly the devices sent in and never watch for new devices - (config.device_files.iter().map(|device_file| InputDevice::open(&device_file).expect("device_file does not exist!")).collect(), None) - } else { - use std::os::unix::io::AsRawFd; - // we want to wait forever starting new threads for any new keyboard devices - // there is a slight race condition here, if a keyboard is plugged in between the time we - // enumerate the devices and set up the inotify watch, we'll miss it, doing it the other way - // can bring duplicates though, todo: think about this... - let device_files = get_keyboard_devices(); - let mut inotify = Inotify::init()?; - inotify.add_watch(INPUT_FOLDER, WatchMask::CREATE)?; - let epoll_event = epoll::Event::new(epoll::Events::EPOLLIN | epoll::Events::EPOLLET, INOTIFY_DATA); - epoll::ctl(epoll_fd, epoll::ControlOptions::EPOLL_CTL_ADD, inotify.as_raw_fd(), epoll_event)?; - (device_files, Some(inotify)) - }; - let mut input_devices = Vec::with_capacity(device_files.len()); - for (idx, device_file) in device_files.into_iter().enumerate() { - input_devices.push(Some(device_file.grab()?.epoll_add(epoll_fd, idx as u64)?)); - } + let (device_files, mut inotify) = if config.device_files.len() > 0 { + // we operate on exactly the devices sent in and never watch for new devices + ( + config + .device_files + .iter() + .map(|device_file| { + InputDevice::open(&device_file).expect("device_file does not exist!") + }) + .collect(), + None, + ) + } else { + use std::os::unix::io::AsRawFd; + // we want to wait forever starting new threads for any new keyboard devices + // there is a slight race condition here, if a keyboard is plugged in between the time we + // enumerate the devices and set up the inotify watch, we'll miss it, doing it the other way + // can bring duplicates though, todo: think about this... + let device_files = get_keyboard_devices(); + let mut inotify = Inotify::init()?; + inotify.add_watch(INPUT_FOLDER, WatchMask::CREATE)?; + let epoll_event = epoll::Event::new( + epoll::Events::EPOLLIN | epoll::Events::EPOLLET, + INOTIFY_DATA, + ); + epoll::ctl( + epoll_fd, + epoll::ControlOptions::EPOLL_CTL_ADD, + inotify.as_raw_fd(), + epoll_event, + )?; + (device_files, Some(inotify)) + }; + let mut input_devices = Vec::with_capacity(device_files.len()); + for (idx, device_file) in device_files.into_iter().enumerate() { + input_devices.push(Some(device_file.grab()?.epoll_add(epoll_fd, idx as u64)?)); + } - let mut epoll_buf = [epoll::Event::new(epoll::Events::empty(), 0); 4]; - let mut inotify_buf = [0u8; 256]; + let mut epoll_buf = [epoll::Event::new(epoll::Events::empty(), 0); 4]; + let mut inotify_buf = [0u8; 256]; - loop { - let num_events = epoll::wait(epoll_fd, -1, &mut epoll_buf)?; - for event in &epoll_buf[0..num_events] { - let idx = event.data as usize; - if let Some(Some(input_device)) = &mut input_devices.get_mut(idx) { - loop { - match input_device.read_event(&mut input_event_buf) { - Ok(event) => { - //println!("input event: {:?}", event); - send_event(&mut key_map, event, &device)? - } - Err(err) => { - if let Error::Io(ref err) = err { - if err.kind() == std::io::ErrorKind::WouldBlock { - // go back to epoll event loop - break; - } + loop { + let num_events = epoll::wait(epoll_fd, -1, &mut epoll_buf)?; + for event in &epoll_buf[0..num_events] { + let idx = event.data as usize; + if let Some(Some(input_device)) = &mut input_devices.get_mut(idx) { + loop { + match input_device.read_event(&mut input_event_buf) { + Ok(event) => { + //println!("input event: {:?}", event); + send_event(&mut key_map, event, &device)? + } + Err(err) => { + if let Error::Io(ref err) = err { + if err.kind() == std::io::ErrorKind::WouldBlock { + // go back to epoll event loop + break; } - // otherwise it's some other error, don't read anything from this again - println!("input err: {:?}", err); - // remove it from input_devices and drop it - let _ = std::mem::replace(&mut input_devices[idx], None); - if inotify.is_none() { - // if we aren't watching with inotify, and the last device is removed (Vec only has None's in it), exit the program - if input_devices.iter().all(|id| id.is_none()) { - println!("last device went away, exiting..."); - return Ok(()); - } - } - break; } + // otherwise it's some other error, don't read anything from this again + println!("input err: {:?}", err); + // remove it from input_devices and drop it + let _ = std::mem::replace(&mut input_devices[idx], None); + if inotify.is_none() { + // if we aren't watching with inotify, and the last device is removed (Vec only has None's in it), exit the program + if input_devices.iter().all(|id| id.is_none()) { + println!("last device went away, exiting..."); + return Ok(()); + } + } + break; } } - } else if event.data == INOTIFY_DATA { - if let Some(inotify) = &mut inotify { - for event in inotify.read_events(&mut inotify_buf)? { - if let Some(device_file) = event.name.and_then(|name| name.to_str()) { - // check if this is an eligible keyboard device - let mut path = std::path::PathBuf::new(); - path.push(INPUT_FOLDER); - path.push(device_file); + } + } else if event.data == INOTIFY_DATA { + if let Some(inotify) = &mut inotify { + for event in inotify.read_events(&mut inotify_buf)? { + if let Some(device_file) = event.name.and_then(|name| name.to_str()) + { + // check if this is an eligible keyboard device + let mut path = std::path::PathBuf::new(); + path.push(INPUT_FOLDER); + path.push(device_file); - if let Ok(input_device) = InputDevice::open(path).and_then(|id| id.valid_keyboard_device()) { - println!("starting mapping for new keyboard: {}", device_file); + if let Ok(input_device) = InputDevice::open(path) + .and_then(|id| id.valid_keyboard_device()) + { + println!( + "starting mapping for new keyboard: {}", + device_file + ); - let idx = input_devices.iter().position(|id| id.is_none()).unwrap_or(input_devices.len()); + let idx = input_devices + .iter() + .position(|id| id.is_none()) + .unwrap_or(input_devices.len()); - let input_device = input_device.grab()?.epoll_add(epoll_fd, idx as u64)?; + let input_device = + input_device.grab()?.epoll_add(epoll_fd, idx as u64)?; - if idx == input_devices.len() { - input_devices.push(Some(input_device)); - } else { - // simply replacing None here - let _ = std::mem::replace(&mut input_devices[idx], Some(input_device)); - } + if idx == input_devices.len() { + input_devices.push(Some(input_device)); + } else { + // simply replacing None here + let _ = std::mem::replace( + &mut input_devices[idx], + Some(input_device), + ); } } } @@ -223,6 +257,7 @@ pub fn main_res() -> Result<()> { } } } + } } } @@ -247,7 +282,12 @@ fn parse_args() -> Config { let mut opts = Options::new(); opts.optflag("h", "help", "prints this help message"); opts.optflag("v", "version", "prints the version"); - opts.optopt("c", "config", "specify the keymap config file to use (default: /etc/rusty-keys/keymap.toml)", "FILE"); + opts.optopt( + "c", + "config", + "specify the keymap config file to use (default: /etc/rusty-keys/keymap.toml)", + "FILE", + ); let matches = opts.parse(&args[1..]); if matches.is_err() { @@ -265,7 +305,9 @@ fn parse_args() -> Config { exit(0); } - let config_file = matches.opt_str("c").unwrap_or("/etc/rusty-keys/keymap.toml".to_owned()); + let config_file = matches + .opt_str("c") + .unwrap_or("/etc/rusty-keys/keymap.toml".to_owned()); Config::new(matches.free, config_file) } @@ -276,7 +318,9 @@ fn get_keyboard_devices() -> Vec { if let Ok(entries) = std::fs::read_dir(INPUT_FOLDER) { for entry in entries { if let Ok(entry) = entry { - if let Ok(input_device) = InputDevice::open(entry.path()).and_then(|id|id.valid_keyboard_device()) { + if let Ok(input_device) = + InputDevice::open(entry.path()).and_then(|id| id.valid_keyboard_device()) + { res.push(input_device); } } @@ -286,314 +330,317 @@ fn get_keyboard_devices() -> Vec { } pub fn key_map() -> HashMap<&'static str, u16> { - [ - // generated like: - // grep -o 'KEY_[^ :;]*' ~/.cargo/registry/src/github.com-1ecc6299db9ec823/uinput-sys-0.1.3/src/codes | sed 's/^KEY_//' | awk '{print "(\""$1"\", KEY_"$1"),"}' - ("RESERVED", KEY_RESERVED), - ("ESC", KEY_ESC), - ("1", KEY_1), - ("2", KEY_2), - ("3", KEY_3), - ("4", KEY_4), - ("5", KEY_5), - ("6", KEY_6), - ("7", KEY_7), - ("8", KEY_8), - ("9", KEY_9), - ("10", KEY_10), - ("MINUS", KEY_MINUS), - ("EQUAL", KEY_EQUAL), - ("BACKSPACE", KEY_BACKSPACE), - ("TAB", KEY_TAB), - ("Q", KEY_Q), - ("W", KEY_W), - ("E", KEY_E), - ("R", KEY_R), - ("T", KEY_T), - ("Y", KEY_Y), - ("U", KEY_U), - ("I", KEY_I), - ("O", KEY_O), - ("P", KEY_P), - ("LEFTBRACE", KEY_LEFTBRACE), - ("RIGHTBRACE", KEY_RIGHTBRACE), - ("ENTER", KEY_ENTER), - ("LEFTCTRL", KEY_LEFTCTRL), - ("A", KEY_A), - ("S", KEY_S), - ("D", KEY_D), - ("F", KEY_F), - ("G", KEY_G), - ("H", KEY_H), - ("J", KEY_J), - ("K", KEY_K), - ("L", KEY_L), - ("SEMICOLON", KEY_SEMICOLON), - ("APOSTROPHE", KEY_APOSTROPHE), - ("GRAVE", KEY_GRAVE), - ("LEFTSHIFT", KEY_LEFTSHIFT), - ("BACKSLASH", KEY_BACKSLASH), - ("Z", KEY_Z), - ("X", KEY_X), - ("C", KEY_C), - ("V", KEY_V), - ("B", KEY_B), - ("N", KEY_N), - ("M", KEY_M), - ("COMMA", KEY_COMMA), - ("DOT", KEY_DOT), - ("SLASH", KEY_SLASH), - ("RIGHTSHIFT", KEY_RIGHTSHIFT), - ("KPASTERISK", KEY_KPASTERISK), - ("LEFTALT", KEY_LEFTALT), - ("SPACE", KEY_SPACE), - ("CAPSLOCK", KEY_CAPSLOCK), - ("F1", KEY_F1), - ("F2", KEY_F2), - ("F3", KEY_F3), - ("F4", KEY_F4), - ("F5", KEY_F5), - ("F6", KEY_F6), - ("F7", KEY_F7), - ("F8", KEY_F8), - ("F9", KEY_F9), - ("F10", KEY_F10), - ("NUMLOCK", KEY_NUMLOCK), - ("SCROLLLOCK", KEY_SCROLLLOCK), - ("KP7", KEY_KP7), - ("KP8", KEY_KP8), - ("KP9", KEY_KP9), - ("KPMINUS", KEY_KPMINUS), - ("KP4", KEY_KP4), - ("KP5", KEY_KP5), - ("KP6", KEY_KP6), - ("KPPLUS", KEY_KPPLUS), - ("KP1", KEY_KP1), - ("KP2", KEY_KP2), - ("KP3", KEY_KP3), - ("KP0", KEY_KP0), - ("KPDOT", KEY_KPDOT), - ("ZENKAKUHANKAKU", KEY_ZENKAKUHANKAKU), - ("102ND", KEY_102ND), - ("F11", KEY_F11), - ("F12", KEY_F12), - ("RO", KEY_RO), - ("KATAKANA", KEY_KATAKANA), - ("HIRAGANA", KEY_HIRAGANA), - ("HENKAN", KEY_HENKAN), - ("KATAKANAHIRAGANA", KEY_KATAKANAHIRAGANA), - ("MUHENKAN", KEY_MUHENKAN), - ("KPJPCOMMA", KEY_KPJPCOMMA), - ("KPENTER", KEY_KPENTER), - ("RIGHTCTRL", KEY_RIGHTCTRL), - ("KPSLASH", KEY_KPSLASH), - ("SYSRQ", KEY_SYSRQ), - ("RIGHTALT", KEY_RIGHTALT), - ("LINEFEED", KEY_LINEFEED), - ("HOME", KEY_HOME), - ("UP", KEY_UP), - ("PAGEUP", KEY_PAGEUP), - ("LEFT", KEY_LEFT), - ("RIGHT", KEY_RIGHT), - ("END", KEY_END), - ("DOWN", KEY_DOWN), - ("PAGEDOWN", KEY_PAGEDOWN), - ("INSERT", KEY_INSERT), - ("DELETE", KEY_DELETE), - ("MACRO", KEY_MACRO), - ("MUTE", KEY_MUTE), - ("VOLUMEDOWN", KEY_VOLUMEDOWN), - ("VOLUMEUP", KEY_VOLUMEUP), - ("POWER", KEY_POWER), - ("KPEQUAL", KEY_KPEQUAL), - ("KPPLUSMINUS", KEY_KPPLUSMINUS), - ("PAUSE", KEY_PAUSE), - ("SCALE", KEY_SCALE), - ("KPCOMMA", KEY_KPCOMMA), - ("HANGEUL", KEY_HANGEUL), - ("HANGUEL", KEY_HANGUEL), - ("HANGEUL", KEY_HANGEUL), - ("HANJA", KEY_HANJA), - ("YEN", KEY_YEN), - ("LEFTMETA", KEY_LEFTMETA), - ("RIGHTMETA", KEY_RIGHTMETA), - ("COMPOSE", KEY_COMPOSE), - ("STOP", KEY_STOP), - ("AGAIN", KEY_AGAIN), - ("PROPS", KEY_PROPS), - ("UNDO", KEY_UNDO), - ("FRONT", KEY_FRONT), - ("COPY", KEY_COPY), - ("OPEN", KEY_OPEN), - ("PASTE", KEY_PASTE), - ("FIND", KEY_FIND), - ("CUT", KEY_CUT), - ("HELP", KEY_HELP), - ("MENU", KEY_MENU), - ("CALC", KEY_CALC), - ("SETUP", KEY_SETUP), - ("SLEEP", KEY_SLEEP), - ("WAKEUP", KEY_WAKEUP), - ("FILE", KEY_FILE), - ("SENDFILE", KEY_SENDFILE), - ("DELETEFILE", KEY_DELETEFILE), - ("XFER", KEY_XFER), - ("PROG1", KEY_PROG1), - ("PROG2", KEY_PROG2), - ("WWW", KEY_WWW), - ("MSDOS", KEY_MSDOS), - ("COFFEE", KEY_COFFEE), - ("SCREENLOCK", KEY_SCREENLOCK), - ("COFFEE", KEY_COFFEE), - ("ROTATE_DISPLAY", KEY_ROTATE_DISPLAY), - ("DIRECTION", KEY_DIRECTION), - ("ROTATE_DISPLAY", KEY_ROTATE_DISPLAY), - ("CYCLEWINDOWS", KEY_CYCLEWINDOWS), - ("MAIL", KEY_MAIL), - ("BOOKMARKS", KEY_BOOKMARKS), - ("COMPUTER", KEY_COMPUTER), - ("BACK", KEY_BACK), - ("FORWARD", KEY_FORWARD), - ("CLOSECD", KEY_CLOSECD), - ("EJECTCD", KEY_EJECTCD), - ("EJECTCLOSECD", KEY_EJECTCLOSECD), - ("NEXTSONG", KEY_NEXTSONG), - ("PLAYPAUSE", KEY_PLAYPAUSE), - ("PREVIOUSSONG", KEY_PREVIOUSSONG), - ("STOPCD", KEY_STOPCD), - ("RECORD", KEY_RECORD), - ("REWIND", KEY_REWIND), - ("PHONE", KEY_PHONE), - ("ISO", KEY_ISO), - ("CONFIG", KEY_CONFIG), - ("HOMEPAGE", KEY_HOMEPAGE), - ("REFRESH", KEY_REFRESH), - ("EXIT", KEY_EXIT), - ("MOVE", KEY_MOVE), - ("EDIT", KEY_EDIT), - ("SCROLLUP", KEY_SCROLLUP), - ("SCROLLDOWN", KEY_SCROLLDOWN), - ("KPLEFTPAREN", KEY_KPLEFTPAREN), - ("KPRIGHTPAREN", KEY_KPRIGHTPAREN), - ("NEW", KEY_NEW), - ("REDO", KEY_REDO), - ("F13", KEY_F13), - ("F14", KEY_F14), - ("F15", KEY_F15), - ("F16", KEY_F16), - ("F17", KEY_F17), - ("F18", KEY_F18), - ("F19", KEY_F19), - ("F20", KEY_F20), - ("F21", KEY_F21), - ("F22", KEY_F22), - ("F23", KEY_F23), - ("F24", KEY_F24), - ("PLAYCD", KEY_PLAYCD), - ("PAUSECD", KEY_PAUSECD), - ("PROG3", KEY_PROG3), - ("PROG4", KEY_PROG4), - ("DASHBOARD", KEY_DASHBOARD), - ("SUSPEND", KEY_SUSPEND), - ("CLOSE", KEY_CLOSE), - ("PLAY", KEY_PLAY), - ("FASTFORWARD", KEY_FASTFORWARD), - ("BASSBOOST", KEY_BASSBOOST), - ("PRINT", KEY_PRINT), - ("HP", KEY_HP), - ("CAMERA", KEY_CAMERA), - ("SOUND", KEY_SOUND), - ("QUESTION", KEY_QUESTION), - ("EMAIL", KEY_EMAIL), - ("CHAT", KEY_CHAT), - ("SEARCH", KEY_SEARCH), - ("CONNECT", KEY_CONNECT), - ("FINANCE", KEY_FINANCE), - ("SPORT", KEY_SPORT), - ("SHOP", KEY_SHOP), - ("ALTERASE", KEY_ALTERASE), - ("CANCEL", KEY_CANCEL), - ("BRIGHTNESSDOWN", KEY_BRIGHTNESSDOWN), - ("BRIGHTNESSUP", KEY_BRIGHTNESSUP), - ("MEDIA", KEY_MEDIA), - ("SWITCHVIDEOMODE", KEY_SWITCHVIDEOMODE), - ("KBDILLUMTOGGLE", KEY_KBDILLUMTOGGLE), - ("KBDILLUMDOWN", KEY_KBDILLUMDOWN), - ("KBDILLUMUP", KEY_KBDILLUMUP), - ("SEND", KEY_SEND), - ("REPLY", KEY_REPLY), - ("FORWARDMAIL", KEY_FORWARDMAIL), - ("SAVE", KEY_SAVE), - ("DOCUMENTS", KEY_DOCUMENTS), - ("BATTERY", KEY_BATTERY), - ("BLUETOOTH", KEY_BLUETOOTH), - ("WLAN", KEY_WLAN), - ("UWB", KEY_UWB), - ("UNKNOWN", KEY_UNKNOWN), - ("VIDEO_NEXT", KEY_VIDEO_NEXT), - ("VIDEO_PREV", KEY_VIDEO_PREV), - ("BRIGHTNESS_CYCLE", KEY_BRIGHTNESS_CYCLE), - ("BRIGHTNESS_AUTO", KEY_BRIGHTNESS_AUTO), - ("BRIGHTNESS_ZERO", KEY_BRIGHTNESS_ZERO), - ("BRIGHTNESS_AUTO", KEY_BRIGHTNESS_AUTO), - ("DISPLAY_OFF", KEY_DISPLAY_OFF), - ("WWAN", KEY_WWAN), - ("WIMAX", KEY_WIMAX), - ("WWAN", KEY_WWAN), - ("RFKILL", KEY_RFKILL), - ("MICMUTE", KEY_MICMUTE), - // below manual shortcuts - ("PSCR", KEY_SYSRQ), - ("SLCK", KEY_SCROLLLOCK), - ("BRK", KEY_PAUSE), - ("GRV", KEY_GRAVE), - ("0", KEY_10), // dumb or named wrong? - ("MINS", KEY_MINUS), - ("EQL", KEY_EQUAL), - ("BSPC", KEY_BACKSPACE), - ("LBRC", KEY_LEFTBRACE), - ("RBRC", KEY_RIGHTBRACE), - ("BSLS", KEY_BACKSLASH), - ("SCLN", KEY_SEMICOLON), - ("QUOT", KEY_APOSTROPHE), - ("ENT", KEY_ENTER), - ("COMM", KEY_COMMA), - ("DOT", KEY_DOT), - ("SLSH", KEY_SLASH), - ("CAPS", KEY_CAPSLOCK), - ("LSFT", KEY_LEFTSHIFT), - ("RSFT", KEY_RIGHTSHIFT), - ("SPC", KEY_SPACE), - ("APP", KEY_COMPOSE), - ("LCTL", KEY_LEFTCTRL), - ("RCTL", KEY_RIGHTCTRL), - ("LALT", KEY_LEFTALT), - ("RALT", KEY_RIGHTALT), - ("LGUI", KEY_LEFTMETA), - ("RGUI", KEY_RIGHTMETA), - ("INS", KEY_INSERT), - ("PGUP", KEY_PAGEUP), - ("PGDN", KEY_PAGEDOWN), - ("DEL", KEY_DELETE), - ("RGHT", KEY_RIGHT), - ("NLCK", KEY_NUMLOCK), - ("PSLS", KEY_KPSLASH), - ("PAST", KEY_KPASTERISK), - ("PMNS", KEY_KPMINUS), - ("P7", KEY_KP7), - ("P8", KEY_KP8), - ("P9", KEY_KP9), - ("P4", KEY_KP4), - ("P5", KEY_KP5), - ("P6", KEY_KP6), - ("PPLS", KEY_KPPLUS), - ("P1", KEY_KP1), - ("P2", KEY_KP2), - ("P3", KEY_KP3), - ("P0", KEY_KP0), - ("PDOT", KEY_KPDOT), - ("PENT", KEY_KPENTER), - ("TOUCHPAD_TOGGLE", KEY_TOUCHPAD_TOGGLE), - ].iter().cloned().map(|(m, v)| (m, v as u16)).collect() - } - + [ + // generated like: + // grep -o 'KEY_[^ :;]*' ~/.cargo/registry/src/github.com-1ecc6299db9ec823/uinput-sys-0.1.3/src/codes | sed 's/^KEY_//' | awk '{print "(\""$1"\", KEY_"$1"),"}' + ("RESERVED", KEY_RESERVED), + ("ESC", KEY_ESC), + ("1", KEY_1), + ("2", KEY_2), + ("3", KEY_3), + ("4", KEY_4), + ("5", KEY_5), + ("6", KEY_6), + ("7", KEY_7), + ("8", KEY_8), + ("9", KEY_9), + ("10", KEY_10), + ("MINUS", KEY_MINUS), + ("EQUAL", KEY_EQUAL), + ("BACKSPACE", KEY_BACKSPACE), + ("TAB", KEY_TAB), + ("Q", KEY_Q), + ("W", KEY_W), + ("E", KEY_E), + ("R", KEY_R), + ("T", KEY_T), + ("Y", KEY_Y), + ("U", KEY_U), + ("I", KEY_I), + ("O", KEY_O), + ("P", KEY_P), + ("LEFTBRACE", KEY_LEFTBRACE), + ("RIGHTBRACE", KEY_RIGHTBRACE), + ("ENTER", KEY_ENTER), + ("LEFTCTRL", KEY_LEFTCTRL), + ("A", KEY_A), + ("S", KEY_S), + ("D", KEY_D), + ("F", KEY_F), + ("G", KEY_G), + ("H", KEY_H), + ("J", KEY_J), + ("K", KEY_K), + ("L", KEY_L), + ("SEMICOLON", KEY_SEMICOLON), + ("APOSTROPHE", KEY_APOSTROPHE), + ("GRAVE", KEY_GRAVE), + ("LEFTSHIFT", KEY_LEFTSHIFT), + ("BACKSLASH", KEY_BACKSLASH), + ("Z", KEY_Z), + ("X", KEY_X), + ("C", KEY_C), + ("V", KEY_V), + ("B", KEY_B), + ("N", KEY_N), + ("M", KEY_M), + ("COMMA", KEY_COMMA), + ("DOT", KEY_DOT), + ("SLASH", KEY_SLASH), + ("RIGHTSHIFT", KEY_RIGHTSHIFT), + ("KPASTERISK", KEY_KPASTERISK), + ("LEFTALT", KEY_LEFTALT), + ("SPACE", KEY_SPACE), + ("CAPSLOCK", KEY_CAPSLOCK), + ("F1", KEY_F1), + ("F2", KEY_F2), + ("F3", KEY_F3), + ("F4", KEY_F4), + ("F5", KEY_F5), + ("F6", KEY_F6), + ("F7", KEY_F7), + ("F8", KEY_F8), + ("F9", KEY_F9), + ("F10", KEY_F10), + ("NUMLOCK", KEY_NUMLOCK), + ("SCROLLLOCK", KEY_SCROLLLOCK), + ("KP7", KEY_KP7), + ("KP8", KEY_KP8), + ("KP9", KEY_KP9), + ("KPMINUS", KEY_KPMINUS), + ("KP4", KEY_KP4), + ("KP5", KEY_KP5), + ("KP6", KEY_KP6), + ("KPPLUS", KEY_KPPLUS), + ("KP1", KEY_KP1), + ("KP2", KEY_KP2), + ("KP3", KEY_KP3), + ("KP0", KEY_KP0), + ("KPDOT", KEY_KPDOT), + ("ZENKAKUHANKAKU", KEY_ZENKAKUHANKAKU), + ("102ND", KEY_102ND), + ("F11", KEY_F11), + ("F12", KEY_F12), + ("RO", KEY_RO), + ("KATAKANA", KEY_KATAKANA), + ("HIRAGANA", KEY_HIRAGANA), + ("HENKAN", KEY_HENKAN), + ("KATAKANAHIRAGANA", KEY_KATAKANAHIRAGANA), + ("MUHENKAN", KEY_MUHENKAN), + ("KPJPCOMMA", KEY_KPJPCOMMA), + ("KPENTER", KEY_KPENTER), + ("RIGHTCTRL", KEY_RIGHTCTRL), + ("KPSLASH", KEY_KPSLASH), + ("SYSRQ", KEY_SYSRQ), + ("RIGHTALT", KEY_RIGHTALT), + ("LINEFEED", KEY_LINEFEED), + ("HOME", KEY_HOME), + ("UP", KEY_UP), + ("PAGEUP", KEY_PAGEUP), + ("LEFT", KEY_LEFT), + ("RIGHT", KEY_RIGHT), + ("END", KEY_END), + ("DOWN", KEY_DOWN), + ("PAGEDOWN", KEY_PAGEDOWN), + ("INSERT", KEY_INSERT), + ("DELETE", KEY_DELETE), + ("MACRO", KEY_MACRO), + ("MUTE", KEY_MUTE), + ("VOLUMEDOWN", KEY_VOLUMEDOWN), + ("VOLUMEUP", KEY_VOLUMEUP), + ("POWER", KEY_POWER), + ("KPEQUAL", KEY_KPEQUAL), + ("KPPLUSMINUS", KEY_KPPLUSMINUS), + ("PAUSE", KEY_PAUSE), + ("SCALE", KEY_SCALE), + ("KPCOMMA", KEY_KPCOMMA), + ("HANGEUL", KEY_HANGEUL), + ("HANGUEL", KEY_HANGUEL), + ("HANGEUL", KEY_HANGEUL), + ("HANJA", KEY_HANJA), + ("YEN", KEY_YEN), + ("LEFTMETA", KEY_LEFTMETA), + ("RIGHTMETA", KEY_RIGHTMETA), + ("COMPOSE", KEY_COMPOSE), + ("STOP", KEY_STOP), + ("AGAIN", KEY_AGAIN), + ("PROPS", KEY_PROPS), + ("UNDO", KEY_UNDO), + ("FRONT", KEY_FRONT), + ("COPY", KEY_COPY), + ("OPEN", KEY_OPEN), + ("PASTE", KEY_PASTE), + ("FIND", KEY_FIND), + ("CUT", KEY_CUT), + ("HELP", KEY_HELP), + ("MENU", KEY_MENU), + ("CALC", KEY_CALC), + ("SETUP", KEY_SETUP), + ("SLEEP", KEY_SLEEP), + ("WAKEUP", KEY_WAKEUP), + ("FILE", KEY_FILE), + ("SENDFILE", KEY_SENDFILE), + ("DELETEFILE", KEY_DELETEFILE), + ("XFER", KEY_XFER), + ("PROG1", KEY_PROG1), + ("PROG2", KEY_PROG2), + ("WWW", KEY_WWW), + ("MSDOS", KEY_MSDOS), + ("COFFEE", KEY_COFFEE), + ("SCREENLOCK", KEY_SCREENLOCK), + ("COFFEE", KEY_COFFEE), + ("ROTATE_DISPLAY", KEY_ROTATE_DISPLAY), + ("DIRECTION", KEY_DIRECTION), + ("ROTATE_DISPLAY", KEY_ROTATE_DISPLAY), + ("CYCLEWINDOWS", KEY_CYCLEWINDOWS), + ("MAIL", KEY_MAIL), + ("BOOKMARKS", KEY_BOOKMARKS), + ("COMPUTER", KEY_COMPUTER), + ("BACK", KEY_BACK), + ("FORWARD", KEY_FORWARD), + ("CLOSECD", KEY_CLOSECD), + ("EJECTCD", KEY_EJECTCD), + ("EJECTCLOSECD", KEY_EJECTCLOSECD), + ("NEXTSONG", KEY_NEXTSONG), + ("PLAYPAUSE", KEY_PLAYPAUSE), + ("PREVIOUSSONG", KEY_PREVIOUSSONG), + ("STOPCD", KEY_STOPCD), + ("RECORD", KEY_RECORD), + ("REWIND", KEY_REWIND), + ("PHONE", KEY_PHONE), + ("ISO", KEY_ISO), + ("CONFIG", KEY_CONFIG), + ("HOMEPAGE", KEY_HOMEPAGE), + ("REFRESH", KEY_REFRESH), + ("EXIT", KEY_EXIT), + ("MOVE", KEY_MOVE), + ("EDIT", KEY_EDIT), + ("SCROLLUP", KEY_SCROLLUP), + ("SCROLLDOWN", KEY_SCROLLDOWN), + ("KPLEFTPAREN", KEY_KPLEFTPAREN), + ("KPRIGHTPAREN", KEY_KPRIGHTPAREN), + ("NEW", KEY_NEW), + ("REDO", KEY_REDO), + ("F13", KEY_F13), + ("F14", KEY_F14), + ("F15", KEY_F15), + ("F16", KEY_F16), + ("F17", KEY_F17), + ("F18", KEY_F18), + ("F19", KEY_F19), + ("F20", KEY_F20), + ("F21", KEY_F21), + ("F22", KEY_F22), + ("F23", KEY_F23), + ("F24", KEY_F24), + ("PLAYCD", KEY_PLAYCD), + ("PAUSECD", KEY_PAUSECD), + ("PROG3", KEY_PROG3), + ("PROG4", KEY_PROG4), + ("DASHBOARD", KEY_DASHBOARD), + ("SUSPEND", KEY_SUSPEND), + ("CLOSE", KEY_CLOSE), + ("PLAY", KEY_PLAY), + ("FASTFORWARD", KEY_FASTFORWARD), + ("BASSBOOST", KEY_BASSBOOST), + ("PRINT", KEY_PRINT), + ("HP", KEY_HP), + ("CAMERA", KEY_CAMERA), + ("SOUND", KEY_SOUND), + ("QUESTION", KEY_QUESTION), + ("EMAIL", KEY_EMAIL), + ("CHAT", KEY_CHAT), + ("SEARCH", KEY_SEARCH), + ("CONNECT", KEY_CONNECT), + ("FINANCE", KEY_FINANCE), + ("SPORT", KEY_SPORT), + ("SHOP", KEY_SHOP), + ("ALTERASE", KEY_ALTERASE), + ("CANCEL", KEY_CANCEL), + ("BRIGHTNESSDOWN", KEY_BRIGHTNESSDOWN), + ("BRIGHTNESSUP", KEY_BRIGHTNESSUP), + ("MEDIA", KEY_MEDIA), + ("SWITCHVIDEOMODE", KEY_SWITCHVIDEOMODE), + ("KBDILLUMTOGGLE", KEY_KBDILLUMTOGGLE), + ("KBDILLUMDOWN", KEY_KBDILLUMDOWN), + ("KBDILLUMUP", KEY_KBDILLUMUP), + ("SEND", KEY_SEND), + ("REPLY", KEY_REPLY), + ("FORWARDMAIL", KEY_FORWARDMAIL), + ("SAVE", KEY_SAVE), + ("DOCUMENTS", KEY_DOCUMENTS), + ("BATTERY", KEY_BATTERY), + ("BLUETOOTH", KEY_BLUETOOTH), + ("WLAN", KEY_WLAN), + ("UWB", KEY_UWB), + ("UNKNOWN", KEY_UNKNOWN), + ("VIDEO_NEXT", KEY_VIDEO_NEXT), + ("VIDEO_PREV", KEY_VIDEO_PREV), + ("BRIGHTNESS_CYCLE", KEY_BRIGHTNESS_CYCLE), + ("BRIGHTNESS_AUTO", KEY_BRIGHTNESS_AUTO), + ("BRIGHTNESS_ZERO", KEY_BRIGHTNESS_ZERO), + ("BRIGHTNESS_AUTO", KEY_BRIGHTNESS_AUTO), + ("DISPLAY_OFF", KEY_DISPLAY_OFF), + ("WWAN", KEY_WWAN), + ("WIMAX", KEY_WIMAX), + ("WWAN", KEY_WWAN), + ("RFKILL", KEY_RFKILL), + ("MICMUTE", KEY_MICMUTE), + // below manual shortcuts + ("PSCR", KEY_SYSRQ), + ("SLCK", KEY_SCROLLLOCK), + ("BRK", KEY_PAUSE), + ("GRV", KEY_GRAVE), + ("0", KEY_10), // dumb or named wrong? + ("MINS", KEY_MINUS), + ("EQL", KEY_EQUAL), + ("BSPC", KEY_BACKSPACE), + ("LBRC", KEY_LEFTBRACE), + ("RBRC", KEY_RIGHTBRACE), + ("BSLS", KEY_BACKSLASH), + ("SCLN", KEY_SEMICOLON), + ("QUOT", KEY_APOSTROPHE), + ("ENT", KEY_ENTER), + ("COMM", KEY_COMMA), + ("DOT", KEY_DOT), + ("SLSH", KEY_SLASH), + ("CAPS", KEY_CAPSLOCK), + ("LSFT", KEY_LEFTSHIFT), + ("RSFT", KEY_RIGHTSHIFT), + ("SPC", KEY_SPACE), + ("APP", KEY_COMPOSE), + ("LCTL", KEY_LEFTCTRL), + ("RCTL", KEY_RIGHTCTRL), + ("LALT", KEY_LEFTALT), + ("RALT", KEY_RIGHTALT), + ("LGUI", KEY_LEFTMETA), + ("RGUI", KEY_RIGHTMETA), + ("INS", KEY_INSERT), + ("PGUP", KEY_PAGEUP), + ("PGDN", KEY_PAGEDOWN), + ("DEL", KEY_DELETE), + ("RGHT", KEY_RIGHT), + ("NLCK", KEY_NUMLOCK), + ("PSLS", KEY_KPSLASH), + ("PAST", KEY_KPASTERISK), + ("PMNS", KEY_KPMINUS), + ("P7", KEY_KP7), + ("P8", KEY_KP8), + ("P9", KEY_KP9), + ("P4", KEY_KP4), + ("P5", KEY_KP5), + ("P6", KEY_KP6), + ("PPLS", KEY_KPPLUS), + ("P1", KEY_KP1), + ("P2", KEY_KP2), + ("P3", KEY_KP3), + ("P0", KEY_KP0), + ("PDOT", KEY_KPDOT), + ("PENT", KEY_KPENTER), + ("TOUCHPAD_TOGGLE", KEY_TOUCHPAD_TOGGLE), + ] + .iter() + .cloned() + .map(|(m, v)| (m, v as u16)) + .collect() +} diff --git a/src/macos/codes.rs b/src/macos/codes.rs index 2ca700d..2a9682d 100644 --- a/src/macos/codes.rs +++ b/src/macos/codes.rs @@ -1,6 +1,5 @@ - -use std::collections::HashMap; use core_graphics::event::CGKeyCode; +use std::collections::HashMap; pub const KEY_RESERVED: CGKeyCode = 0x31; pub const KEY_ESC: CGKeyCode = 0x00; @@ -564,5 +563,9 @@ pub fn key_map() -> HashMap<&'static str, CGKeyCode> { ("P0", KEY_KP0), ("PDOT", KEY_KPDOT), ("PENT", KEY_KPENTER), - ].iter().cloned().map(|(m, v)| (m, v)).collect() + ] + .iter() + .cloned() + .map(|(m, v)| (m, v)) + .collect() } diff --git a/src/macos/mod.rs b/src/macos/mod.rs index 00fe1bd..31ee15c 100644 --- a/src/macos/mod.rs +++ b/src/macos/mod.rs @@ -4,8 +4,7 @@ #![allow(improper_ctypes)] use crate::*; -use std::env; -use std::process::exit; +use std::{env, process::exit}; use getopts::Options; use std::fs::File; @@ -13,9 +12,10 @@ use std::fs::File; pub mod codes; use codes::*; -use core_graphics::event::CGKeyCode; -use core_graphics::event::*; -use core_graphics::event_source::*; +use core_graphics::{ + event::{CGKeyCode, *}, + event_source::*, +}; use core_graphics::event::{CGEventTapLocation, CGEventType}; @@ -62,8 +62,12 @@ impl KeyEvent for CGEvent { KEY_CAPSLOCK => NX_DEVICECAPSLOCKMASK, _ => panic!("unhandled key: {}", self.code()), }; - if (flags & mask) != 0 { KeyState::DOWN } else { KeyState::UP } - }, + if (flags & mask) != 0 { + KeyState::DOWN + } else { + KeyState::UP + } + } CGEventType::KeyDown => KeyState::DOWN, CGEventType::KeyUp => KeyState::UP, CGEventType::TapDisabledByTimeout => { @@ -71,11 +75,11 @@ impl KeyEvent for CGEvent { todo!("implement register listener"); //register_listener(channel); //KeyState::OTHER - }, + } _ => { println!("Received unknown EventType: {:?}", event_type); KeyState::OTHER - }, + } } } } @@ -99,15 +103,21 @@ impl Keyboard> for CGEventSource { self.send_mod_code_value(code, event.value() == KeyState::UP, event) } - fn send_mod_code_value(&self, code: CGKeyCode, up_not_down: bool, _event: &mut CGEvent) -> Result> { + fn send_mod_code_value( + &self, + code: CGKeyCode, + up_not_down: bool, + _event: &mut CGEvent, + ) -> Result> { //println!("send_mod_code_value orig: {} code: {}, up_not_down: {}", event.code(), code, up_not_down); //return Ok(None); - let event = - CGEvent::new_keyboard_event(self.clone(), code, !up_not_down) - .expect("Failed creating event"); + let event = CGEvent::new_keyboard_event(self.clone(), code, !up_not_down) + .expect("Failed creating event"); match tapLocation { - CGEventTapLocation::HID => event.set_integer_value_field(EventField::EVENT_SOURCE_USER_DATA, uniqueHIDUserData), + CGEventTapLocation::HID => { + event.set_integer_value_field(EventField::EVENT_SOURCE_USER_DATA, uniqueHIDUserData) + } _ => {} }; event.post(tapLocation); @@ -146,12 +156,14 @@ pub fn main_res() -> Result<()> { let key_maps = MacOSKeyMaps::from_cfg(&key_map, &config.config_file); //println!("key_maps: {}", key_maps); - let callback_pointer: CallbackPointer = (key_maps, CGEventSource::new(CGEventSourceStateID::Private).expect("Failed creating event source")); + let callback_pointer: CallbackPointer = ( + key_maps, + CGEventSource::new(CGEventSourceStateID::Private).expect("Failed creating event source"), + ); let mask = CGEventMaskBit(CGEventType::KeyDown) | CGEventMaskBit(CGEventType::KeyUp) - | CGEventMaskBit(CGEventType::FlagsChanged) - ; + | CGEventMaskBit(CGEventType::FlagsChanged); unsafe { let options = 0; @@ -191,12 +203,14 @@ pub fn main_res() -> Result<()> { #[derive(Debug)] struct Config { - config_file: String + config_file: String, } impl Config { fn new(config_file: String) -> Self { - Config { config_file: config_file } + Config { + config_file: config_file, + } } } @@ -224,7 +238,10 @@ fn parse_args() -> Config { default_configs.push("keymap.toml".to_string()); - let c_msg = format!("specify the keymap config file to use (default in order: {:?})", default_configs); + let c_msg = format!( + "specify the keymap config file to use (default in order: {:?})", + default_configs + ); let mut opts = Options::new(); opts.optflag("h", "help", "prints this help message"); @@ -278,117 +295,119 @@ type CGEventTapOptions = u32; type CGEventTapPlacement = u32; // Callback Type -type CGEventTapCallBack = extern "C" fn(Pointer, CGEventType, CGEvent, &mut CallbackPointer) -> CGEvent; +type CGEventTapCallBack = + extern "C" fn(Pointer, CGEventType, CGEvent, &mut CallbackPointer) -> CGEvent; // Constants const kCGSessionEventTap: CGEventTapLocation = CGEventTapLocation::HID; const kCGHeadInsertEventTap: CGEventTapPlacement = 0; - // Link to ApplicationServices/ApplicationServices.h and Carbon/Carbon.h - #[link(name = "ApplicationServices", kind = "framework")] - #[link(name = "Carbon", kind = "framework")] - extern { +// Link to ApplicationServices/ApplicationServices.h and Carbon/Carbon.h +#[link(name = "ApplicationServices", kind = "framework")] +#[link(name = "Carbon", kind = "framework")] +extern "C" { - /// Pass through to the default loop modes - pub static kCFRunLoopCommonModes: Pointer; + /// Pass through to the default loop modes + pub static kCFRunLoopCommonModes: Pointer; - /// Pass through to the default allocator - pub static kCFAllocatorDefault: Pointer; + /// Pass through to the default allocator + pub static kCFAllocatorDefault: Pointer; - /// Run the current threads loop in default mode - pub fn CFRunLoopRun(); + /// Run the current threads loop in default mode + pub fn CFRunLoopRun(); - /// Obtain the current threads loop - pub fn CFRunLoopGetCurrent() -> Pointer; + /// Obtain the current threads loop + pub fn CFRunLoopGetCurrent() -> Pointer; - /// Create an event tap - /// - /// # Arguments - /// - /// * `place` - The location of the new event tap. Pass one of - /// the constants listed in Event Tap Locations. Only - /// processes running as the root user may locate an - /// event tap at the point where HID events enter the - /// window server; for other users, this function - /// returns NULL. - /// - /// * `options` - The placement of the new event tap in the - /// list of active event taps. Pass one of the - /// constants listed in Event Tap Placement. - /// - /// * `eventsOfInterest` - A constant that specifies whether - /// the new event tap is a passive listener or an - /// active filter. - /// - /// * `callback` - A bit mask that specifies the set of events - /// to be observed. For a list of possible events, - /// see Event Types. For information on how to - /// specify the mask, see CGEventMask. If the event - /// tap is not permitted to monitor one or more of - /// the events specified in the eventsOfInterest - /// parameter, then the appropriate bits in the mask - /// are cleared. If that action results in an empty - /// mask, this function returns NULL. callback - /// - /// * `refcon` - An event tap callback function that you - /// provide. Your callback function is invoked from - /// the run loop to which the event tap is added as a - /// source. The thread safety of the callback is - /// defined by the run loop’s environment. To learn - /// more about event tap callbacks, see - /// CGEventTapCallBack. refcon - /// - /// * `channel` - A pointer to user-defined data. This pointer - /// is passed into the callback function specified in - /// the callback parameter. Here we use it as a mpsc - /// channel. - pub fn CGEventTapCreate( - tap: CGEventTapLocation, - place: CGEventTapPlacement, - options: CGEventTapOptions, - eventsOfInterest: CGEventMask, - callback: CGEventTapCallBack, - channel: &CallbackPointer, - ) -> CFMachPortRef; + /// Create an event tap + /// + /// # Arguments + /// + /// * `place` - The location of the new event tap. Pass one of + /// the constants listed in Event Tap Locations. Only + /// processes running as the root user may locate an + /// event tap at the point where HID events enter the + /// window server; for other users, this function + /// returns NULL. + /// + /// * `options` - The placement of the new event tap in the + /// list of active event taps. Pass one of the + /// constants listed in Event Tap Placement. + /// + /// * `eventsOfInterest` - A constant that specifies whether + /// the new event tap is a passive listener or an + /// active filter. + /// + /// * `callback` - A bit mask that specifies the set of events + /// to be observed. For a list of possible events, + /// see Event Types. For information on how to + /// specify the mask, see CGEventMask. If the event + /// tap is not permitted to monitor one or more of + /// the events specified in the eventsOfInterest + /// parameter, then the appropriate bits in the mask + /// are cleared. If that action results in an empty + /// mask, this function returns NULL. callback + /// + /// * `refcon` - An event tap callback function that you + /// provide. Your callback function is invoked from + /// the run loop to which the event tap is added as a + /// source. The thread safety of the callback is + /// defined by the run loop’s environment. To learn + /// more about event tap callbacks, see + /// CGEventTapCallBack. refcon + /// + /// * `channel` - A pointer to user-defined data. This pointer + /// is passed into the callback function specified in + /// the callback parameter. Here we use it as a mpsc + /// channel. + pub fn CGEventTapCreate( + tap: CGEventTapLocation, + place: CGEventTapPlacement, + options: CGEventTapOptions, + eventsOfInterest: CGEventMask, + callback: CGEventTapCallBack, + channel: &CallbackPointer, + ) -> CFMachPortRef; - /// Creates a CFRunLoopSource object for a CFMachPort - /// object. - /// - /// The run loop source is not automatically added to - /// a run loop. To add the source to a run loop, use - /// CFRunLoopAddSource - pub fn CFMachPortCreateRunLoopSource( - allocator: Pointer, - port: CFMachPortRef, - order: libc::c_int, - ) -> Pointer; + /// Creates a CFRunLoopSource object for a CFMachPort + /// object. + /// + /// The run loop source is not automatically added to + /// a run loop. To add the source to a run loop, use + /// CFRunLoopAddSource + pub fn CFMachPortCreateRunLoopSource( + allocator: Pointer, + port: CFMachPortRef, + order: libc::c_int, + ) -> Pointer; - /// Adds a CFRunLoopSource object to a run loop mode. - pub fn CFRunLoopAddSource( - run_loop: Pointer, - run_loop_source: Pointer, - mode: Pointer, - ); + /// Adds a CFRunLoopSource object to a run loop mode. + pub fn CFRunLoopAddSource(run_loop: Pointer, run_loop_source: Pointer, mode: Pointer); - pub fn CGEventTapEnable(port: CFMachPortRef, enable: bool); - } + pub fn CGEventTapEnable(port: CFMachPortRef, enable: bool); +} -const NX_DEVICELCTLKEYMASK: u64 = 0x00000001; +const NX_DEVICELCTLKEYMASK: u64 = 0x00000001; const NX_DEVICERCTLKEYMASK: u64 = 0x00002000; -const NX_DEVICELSHIFTKEYMASK: u64 = 0x00000002; -const NX_DEVICERSHIFTKEYMASK: u64 = 0x00000004; -const NX_DEVICELCMDKEYMASK: u64 = 0x00000008; -const NX_DEVICERCMDKEYMASK: u64 = 0x00000010; -const NX_DEVICELALTKEYMASK: u64 = 0x00000020; -const NX_DEVICERALTKEYMASK: u64 = 0x00000040; +const NX_DEVICELSHIFTKEYMASK: u64 = 0x00000002; +const NX_DEVICERSHIFTKEYMASK: u64 = 0x00000004; +const NX_DEVICELCMDKEYMASK: u64 = 0x00000008; +const NX_DEVICERCMDKEYMASK: u64 = 0x00000010; +const NX_DEVICELALTKEYMASK: u64 = 0x00000020; +const NX_DEVICERALTKEYMASK: u64 = 0x00000040; -const NX_DEVICECAPSLOCKMASK: u64 = 1 << 16; +const NX_DEVICECAPSLOCKMASK: u64 = 1 << 16; /// This callback will be registered to be invoked from the run loop /// to which the event tap is added as a source. #[no_mangle] #[allow(unused_variables, improper_ctypes_definitions)] -pub extern fn callback(proxy: Pointer, event_type: CGEventType, mut event: CGEvent, callback_pointer: &mut CallbackPointer) -> CGEvent { +pub extern "C" fn callback( + proxy: Pointer, + event_type: CGEventType, + mut event: CGEvent, + callback_pointer: &mut CallbackPointer, +) -> CGEvent { let (key_maps, event_source) = callback_pointer; match tapLocation { CGEventTapLocation::HID => { @@ -400,15 +419,16 @@ pub extern fn callback(proxy: Pointer, event_type: CGEventType, mut event: CGEve _ => {} }; - key_maps.send_event(&mut event, &event_source).expect("macos shouldn't error...") + key_maps + .send_event(&mut event, &event_source) + .expect("macos shouldn't error...") .unwrap_or_else(|| { event.set_type(CGEventType::Null); event }) // None means return NULL - } - - /// Redefine macro for bitshifting from header as function here - pub fn CGEventMaskBit(eventType: CGEventType) -> CGEventMask { - 1 << (eventType as u32) - } +} +/// Redefine macro for bitshifting from header as function here +pub fn CGEventMaskBit(eventType: CGEventType) -> CGEventMask { + 1 << (eventType as u32) +} diff --git a/src/main.rs b/src/main.rs index e073df4..08f08f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ - #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] fn main() { let ret = rusty_keys::main_res(); diff --git a/src/windows/codes.rs b/src/windows/codes.rs index a2381a7..3e45a46 100644 --- a/src/windows/codes.rs +++ b/src/windows/codes.rs @@ -1,6 +1,5 @@ +use std::{collections::HashMap, convert::TryFrom}; use winapi::shared::minwindef::DWORD; -use std::collections::HashMap; -use std::convert::TryFrom; // https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes @@ -557,7 +556,11 @@ pub fn key_map() -> HashMap<&'static str, USizeableDWORD> { ("P0", KEY_KP0), ("PDOT", KEY_KPDOT), ("PENT", KEY_KPENTER), - ].iter().cloned().map(|(m, v)| (m, USizeableDWORD(v))).collect() + ] + .iter() + .cloned() + .map(|(m, v)| (m, USizeableDWORD(v))) + .collect() } // https://www.reddit.com/r/rust/comments/9xth8g/why_no_from_conversion_from_u32_to_usize/ @@ -576,4 +579,4 @@ impl TryFrom for USizeableDWORD { fn try_from(value: usize) -> ::std::result::Result { Ok(USizeableDWORD(value as DWORD)) } -} \ No newline at end of file +} diff --git a/src/windows/mod.rs b/src/windows/mod.rs index 4430cc6..b1c9eeb 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -1,24 +1,32 @@ #![windows_subsystem = "windows"] use crate::*; -use std::env; -use std::process::exit; +use std::{env, process::exit}; use getopts::Options; use std::fs::File; -use winapi::um::winuser::{KBDLLHOOKSTRUCT, WH_KEYBOARD_LL, MSG, GetMessageW, CallNextHookEx, SetWindowsHookExW, INPUT_KEYBOARD, MapVirtualKeyW, LPINPUT, INPUT, KEYBDINPUT, SendInput, KEYEVENTF_SCANCODE, KEYEVENTF_KEYUP, WM_KEYUP, WM_KEYDOWN, MAPVK_VK_TO_VSC, ShowWindow, SW_HIDE}; -use winapi::shared::windef::{HHOOK__, HWND}; -use winapi::shared::minwindef::{LRESULT, WPARAM, LPARAM, HINSTANCE}; -use winapi::shared::basetsd::ULONG_PTR; -use winapi::ctypes::c_int; +use winapi::{ + ctypes::c_int, + shared::{ + basetsd::ULONG_PTR, + minwindef::{HINSTANCE, LPARAM, LRESULT, WPARAM}, + windef::{HHOOK__, HWND}, + }, + um::winuser::{ + CallNextHookEx, GetMessageW, MapVirtualKeyW, SendInput, SetWindowsHookExW, ShowWindow, + INPUT, INPUT_KEYBOARD, KBDLLHOOKSTRUCT, KEYBDINPUT, KEYEVENTF_KEYUP, KEYEVENTF_SCANCODE, + LPINPUT, MAPVK_VK_TO_VSC, MSG, SW_HIDE, WH_KEYBOARD_LL, WM_KEYDOWN, WM_KEYUP, + }, +}; pub mod codes; use codes::*; -use std::sync::atomic::{AtomicPtr, Ordering}; -use std::mem::{zeroed, size_of}; -use winapi::_core::ptr::null_mut; -use winapi::_core::mem::transmute_copy; +use std::{ + mem::{size_of, zeroed}, + sync::atomic::{AtomicPtr, Ordering}, +}; +use winapi::_core::{mem::transmute_copy, ptr::null_mut}; use lazy_static::lazy_static; use std::sync::Mutex; @@ -65,7 +73,12 @@ impl Keyboard for Device { self.send_mod_code_value(code, event.value as u32 == WM_KEYUP, event) } - fn send_mod_code_value(&self, code: USizeableDWORD, up_not_down: bool, _event: &mut InputEvent) -> Result { + fn send_mod_code_value( + &self, + code: USizeableDWORD, + up_not_down: bool, + _event: &mut InputEvent, + ) -> Result { let flags = if up_not_down { KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP } else { @@ -132,7 +145,7 @@ unsafe extern "system" fn keybd_proc(code: c_int, w_param: WPARAM, l_param: LPAR kb_struct.vkCode, kb_struct.scanCode, kb_struct.flags, kb_struct.time, kb_struct.dwExtraInfo); */ - let mut input_event = InputEvent{ + let mut input_event = InputEvent { code, value: w_param, kb_hook_pointer: l_param, @@ -142,13 +155,17 @@ unsafe extern "system" fn keybd_proc(code: c_int, w_param: WPARAM, l_param: LPAR // .unwrap() is ok because windows impl can actually never can fail //DEVICE.send(&mut input_event).unwrap() //KEY_MAPPER.send_event(&mut input_event, &DEVICE).unwrap() - KEY_MAPPER.lock().unwrap().send_event(&mut input_event, &DEVICE).unwrap() + KEY_MAPPER + .lock() + .unwrap() + .send_event(&mut input_event, &DEVICE) + .unwrap() } fn set_hook( hook_id: i32, hook_ptr: &AtomicPtr, - hook_proc: unsafe extern "system" fn (c_int, WPARAM, LPARAM) -> LRESULT, + hook_proc: unsafe extern "system" fn(c_int, WPARAM, LPARAM) -> LRESULT, ) { hook_ptr.store( unsafe { SetWindowsHookExW(hook_id, Some(hook_proc), 0 as HINSTANCE, 0) }, @@ -172,7 +189,6 @@ fn send_keybd_input(flags: u32, key_code: USizeableDWORD) { unsafe { SendInput(1, &mut input as LPINPUT, size_of::() as c_int) }; } - pub fn main_res() -> Result<()> { // this is just to cause the lazy_static init to run first, so if -h or -v is wanted, we do that // and exit immediately... todo: how to avoid mutex/lazy_static entirely??? @@ -188,25 +204,27 @@ pub fn main_res() -> Result<()> { // hide window // todo: probably should be tray icon someplace in future to quit, and error messages as windows popups etc... let hwnd = GetConsoleWindow(); - ShowWindow( hwnd, SW_HIDE ); + ShowWindow(hwnd, SW_HIDE); } - + let mut msg: MSG = unsafe { zeroed() }; unsafe { GetMessageW(&mut msg, 0 as HWND, 0, 0) }; - + //std::thread::sleep(std::time::Duration::from_millis(400000)); - + Ok(()) } #[derive(Debug)] struct Config { - config_file: String + config_file: String, } impl Config { fn new(config_file: String) -> Self { - Config { config_file: config_file } + Config { + config_file: config_file, + } } } @@ -227,14 +245,17 @@ fn parse_args() -> Config { } let args: Vec<_> = env::args().collect(); - + let mut default_configs = Vec::new(); get_env_push("USERPROFILE", "\\keymap.toml", &mut default_configs); get_env_push("APPDATA", "\\keymap.toml", &mut default_configs); - + default_configs.push("keymap.toml".to_string()); - - let c_msg = format!("specify the keymap config file to use (default in order: {:?})", default_configs); + + let c_msg = format!( + "specify the keymap config file to use (default in order: {:?})", + default_configs + ); let mut opts = Options::new(); opts.optflag("h", "help", "prints this help message");