#[allow(warnings)]
#[cfg(feature = "keyboard")]
pub mod keyboard {
pub mod common {}
#[cfg(target_os = "linux")]
pub mod linux {
#[cfg(target_os = "linux")]
pub fn key_press(keys: &str) {
use xdotool::command::options;
use xdotool::keyboard::send_key_down;
use xdotool::keyboard::send_key_up;
use xdotool::option_vec;
use xdotool::OptionVec;
send_key_down(keys, option_vec![options::KeyboardOption::Delay(100)]);
}
#[cfg(target_os = "linux")]
pub fn key_release(keys: &str) {
use xdotool::command::options;
use xdotool::keyboard::send_key_down;
use xdotool::keyboard::send_key_up;
use xdotool::option_vec;
use xdotool::OptionVec;
send_key_up(keys, option_vec![options::KeyboardOption::Delay(100)]);
}
}
#[cfg(target_os = "macos")]
pub mod macos {
#[cfg(target_os = "macos")]
pub fn key_press(keycode: u16) {
use core_graphics::event::CGKeyCode;
use core_graphics::event::{CGEvent, CGEventFlags, CGEventTapLocation};
use core_graphics::event_source::CGEventSource;
use core_graphics::event_source::CGEventSourceStateID;
let state_id: CGEventSourceStateID = CGEventSourceStateID::HIDSystemState;
let source: CGEventSource = CGEventSource::new(state_id).unwrap();
let new_keycode: CGKeyCode = keycode;
let event = CGEvent::new_keyboard_event(source, new_keycode, true).unwrap();
event.set_flags(CGEventFlags::CGEventFlagCommand);
event.post(CGEventTapLocation::HID);
}
#[cfg(target_os = "macos")]
pub fn key_release(keycode: u16) {
use core_graphics::event::CGKeyCode;
use core_graphics::event::{CGEvent, CGEventFlags, CGEventTapLocation};
use core_graphics::event_source::CGEventSource;
use core_graphics::event_source::CGEventSourceStateID;
let state_id: CGEventSourceStateID = CGEventSourceStateID::HIDSystemState;
let source: CGEventSource = CGEventSource::new(state_id).unwrap();
let new_keycode: CGKeyCode = keycode;
let event = CGEvent::new_keyboard_event(source, new_keycode, false).unwrap();
event.set_flags(CGEventFlags::CGEventFlagCommand);
event.post(CGEventTapLocation::HID);
}
}
#[cfg(target_os = "windows")]
pub mod windows {
pub fn key_release_keybd_event(keycode: u16) {
use winapi::um::winuser::keybd_event;
unsafe {
keybd_event(keycode as u8, 0, 0x2, 0);
}
}
pub fn key_press_by_keybd_event(keycode: u16) {
use winapi::um::winuser::keybd_event;
use winapi::um::winuser::mouse_event;
unsafe {
keybd_event(keycode as u8, 0, 0, 0);
}
}
pub fn key_release(keycode: u16) {
use winapi::shared::minwindef::DWORD;
use winapi::um::winuser::keybd_event;
use winapi::um::winuser::{SendInput, INPUT, INPUT_KEYBOARD};
pub const KEYEVENTF_KEYUP: DWORD = 0x0002;
unsafe {
let mut input = INPUT::default();
input.type_ = INPUT_KEYBOARD;
input.u.ki_mut().wVk = keycode as _;
input.u.ki_mut().dwFlags = KEYEVENTF_KEYUP;
let usent = SendInput(
1, &mut input as *mut _, std::mem::size_of::<INPUT>() as i32,
);
if usent != 1 {
println!("send error");
}
}
}
pub fn key_press(keycode: u16) {
use winapi::shared::minwindef::DWORD;
use winapi::um::winuser::keybd_event;
use winapi::um::winuser::{SendInput, INPUT, INPUT_KEYBOARD};
pub const KEYEVENTF_KEYUP: DWORD = 0x0002;
unsafe {
let mut input = INPUT::default();
input.type_ = INPUT_KEYBOARD;
input.u.ki_mut().wVk = keycode as _;
input.u.ki_mut().dwFlags = 0; let usent = SendInput(
1, &mut input as *mut _, std::mem::size_of::<INPUT>() as i32,
);
if usent != 1 {
println!("send error");
}
}
}
}
pub use common::*;
#[cfg(target_os = "linux")]
pub use linux::*;
#[cfg(target_os = "macos")]
pub use macos::*;
#[cfg(target_os = "windows")]
pub use windows::*;
}
#[cfg(feature = "keyboard")]
pub use keyboard::*;
#[allow(warnings)]
pub struct WinKeyCode;
impl WinKeyCode {
pub const A: u16 = 65;
pub const B: u16 = 66;
pub const C: u16 = 67;
pub const D: u16 = 68;
pub const E: u16 = 69;
pub const F: u16 = 70;
pub const G: u16 = 71;
pub const H: u16 = 72;
pub const I: u16 = 73;
pub const J: u16 = 74;
pub const K: u16 = 75;
pub const L: u16 = 76;
pub const M: u16 = 77;
pub const N: u16 = 78;
pub const O: u16 = 79;
pub const P: u16 = 80;
pub const Q: u16 = 81;
pub const R: u16 = 82;
pub const S: u16 = 83;
pub const T: u16 = 84;
pub const U: u16 = 85;
pub const V: u16 = 86;
pub const W: u16 = 87;
pub const X: u16 = 88;
pub const Y: u16 = 89;
pub const Z: u16 = 90;
pub const NUM_0: u16 = 48;
pub const NUM_1: u16 = 49;
pub const NUM_2: u16 = 50;
pub const NUM_3: u16 = 51;
pub const NUM_4: u16 = 52;
pub const NUM_5: u16 = 53;
pub const NUM_6: u16 = 54;
pub const NUM_7: u16 = 55;
pub const NUM_8: u16 = 56;
pub const NUM_9: u16 = 57;
pub const F1: u16 = 112;
pub const F2: u16 = 113;
pub const F3: u16 = 114;
pub const F4: u16 = 115;
pub const F5: u16 = 116;
pub const F6: u16 = 117;
pub const F7: u16 = 118;
pub const F8: u16 = 119;
pub const F9: u16 = 120;
pub const F10: u16 = 121;
pub const F11: u16 = 122;
pub const F12: u16 = 123;
pub const ENTER: u16 = 10;
pub const END: u16 = 35;
pub const HOME: u16 = 36;
pub const LEFT_ARROW: u16 = 37;
pub const UP_ARROW: u16 = 38;
pub const RIGHT_ARROW: u16 = 39;
pub const DOWN_ARROW: u16 = 40;
pub const INSERT: u16 = 45;
pub const DELETE: u16 = 46;
pub const HELP: u16 = 47;
pub const NUM_LOCK: u16 = 14;
pub const BACKSPACE: u16 = 8;
pub const TAB: u16 = 9;
pub const CLEAR: u16 = 12;
pub const SHIFT: u16 = 16;
pub const CONTROL: u16 = 17;
pub const ALT: u16 = 18;
pub const CAPS_LOCK: u16 = 20;
pub const ESC: u16 = 27;
pub const SPACEBAR: u16 = 32;
pub const PAGE_UP: u16 = 33;
pub const PAGE_DOWN: u16 = 3;
pub const SIGN_MUL: u16 = 106; pub const SIGN_ADD: u16 = 107; pub const SIGN_SUB: u16 = 109; pub const SIGN_DOT: u16 = 110; pub const SIGN_DIV: u16 = 111; }
#[allow(warnings)]
pub struct KeyCode;
#[allow(warnings)]
impl KeyCode {
pub const RETURN: u16 = 0x24;
pub const TAB: u16 = 0x30;
pub const SPACE: u16 = 0x31;
pub const DELETE: u16 = 0x33;
pub const ESCAPE: u16 = 0x35;
pub const COMMAND: u16 = 0x37;
pub const SHIFT: u16 = 0x38;
pub const CAPS_LOCK: u16 = 0x39;
pub const OPTION: u16 = 0x3A;
pub const CONTROL: u16 = 0x3B;
pub const RIGHT_COMMAND: u16 = 0x36;
pub const RIGHT_SHIFT: u16 = 0x3C;
pub const RIGHT_OPTION: u16 = 0x3D;
pub const RIGHT_CONTROL: u16 = 0x3E;
pub const FUNCTION: u16 = 0x3F;
pub const VOLUME_UP: u16 = 0x48;
pub const VOLUME_DOWN: u16 = 0x49;
pub const MUTE: u16 = 0x4A;
pub const F1: u16 = 0x7A;
pub const F2: u16 = 0x78;
pub const F3: u16 = 0x63;
pub const F4: u16 = 0x76;
pub const F5: u16 = 0x60;
pub const F6: u16 = 0x61;
pub const F7: u16 = 0x62;
pub const F8: u16 = 0x64;
pub const F9: u16 = 0x65;
pub const F10: u16 = 0x6D;
pub const F11: u16 = 0x67;
pub const F12: u16 = 0x6F;
pub const F13: u16 = 0x69;
pub const F14: u16 = 0x6B;
pub const F15: u16 = 0x71;
pub const F16: u16 = 0x6A;
pub const F17: u16 = 0x40;
pub const F18: u16 = 0x4F;
pub const F19: u16 = 0x50;
pub const F20: u16 = 0x5A;
pub const HELP: u16 = 0x72;
pub const HOME: u16 = 0x73;
pub const PAGE_UP: u16 = 0x74;
pub const FORWARD_DELETE: u16 = 0x75;
pub const END: u16 = 0x77;
pub const PAGE_DOWN: u16 = 0x79;
pub const LEFT_ARROW: u16 = 0x7B;
pub const RIGHT_ARROW: u16 = 0x7C;
pub const DOWN_ARROW: u16 = 0x7D;
pub const UP_ARROW: u16 = 0x7E;
pub const A: u16 = 0x00;
pub const B: u16 = 0x0B;
pub const C: u16 = 0x08;
pub const D: u16 = 0x02;
pub const E: u16 = 0x0E;
pub const F: u16 = 0x03;
pub const G: u16 = 0x05;
pub const H: u16 = 0x04;
pub const I: u16 = 0x22;
pub const J: u16 = 0x26;
pub const K: u16 = 0x28;
pub const L: u16 = 0x25;
pub const M: u16 = 0x2E;
pub const N: u16 = 0x2D;
pub const O: u16 = 0x1F;
pub const P: u16 = 0x23;
pub const Q: u16 = 0x0C;
pub const R: u16 = 0x0F;
pub const S: u16 = 0x01;
pub const T: u16 = 0x11;
pub const U: u16 = 0x20;
pub const V: u16 = 0x09;
pub const W: u16 = 0x0D;
pub const X: u16 = 0x07;
pub const Y: u16 = 0x10;
pub const Z: u16 = 0x06;
pub const NUM_0: u16 = 0x1D;
pub const NUM_1: u16 = 0x12;
pub const NUM_2: u16 = 0x13;
pub const NUM_3: u16 = 0x14;
pub const NUM_4: u16 = 0x15;
pub const NUM_5: u16 = 0x17;
pub const NUM_6: u16 = 0x16;
pub const NUM_7: u16 = 0x1A;
pub const NUM_8: u16 = 0x1C;
pub const NUM_9: u16 = 0x19;
}