robot-rust/src/lib.rs
2020-12-17 00:04:14 +09:00

87 lines
2.2 KiB
Rust

#[cfg(target_os = "windows")]
mod windows;
#[cfg(target_os = "windows")]
pub use crate::windows::*;
use crate::keyboard::Key;
use crate::mouse::Button;
use serde::{Deserialize, Serialize};
pub mod keyboard;
pub mod mouse;
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub enum EventListenType {
Mouse,
Keyboard,
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
pub enum EventType {
KeyPress(Key),
KeyRelease(Key),
MousePress(Button),
MouseRelease(Button),
MouseMoveTo { x: f64, y: f64 },
}
// #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
// pub struct Event {
// pub time: SystemTime,
// pub event_type: EventType,
// }
// pub enum BlockInput {
// Block,
// DontBlock,
// }
// pub enum Bind {
// NormalBind(BindHandler),
// BlockBind(BlockBindHandler),
// BlockableBind(BlockableBindHandler),
// }
// pub type BindHandler = Arc<dyn Fn(Event) + Send + Sync + 'static>;
// pub type BlockBindHandler = Arc<dyn Fn(Event) + Send + Sync + 'static>;
// pub type BlockableBindHandler = Arc<dyn Fn(Event) -> BlockInput + Send + Sync + 'static>;
// pub type EventBindMap = HashMap<EventListenType, Bind>;
// pub static EVENT_BINDS: Lazy<Mutex<EventBindMap>> = Lazy::new(|| Mutex::new(EventBindMap::new()));
pub struct Robot;
// impl Robot {
// pub fn bind<F: Fn(Event) + Send + Sync + 'static>(listen_type: EventListenType, callback: F) {
// EVENT_BINDS
// .lock()
// .unwrap()
// .insert(listen_type, Bind::NormalBind(Arc::new(callback)));
// }
// pub fn block_bind<F: Fn(Event) + Send + Sync + 'static>(
// listen_type: EventListenType,
// callback: F,
// ) {
// EVENT_BINDS
// .lock()
// .unwrap()
// .insert(listen_type, Bind::BlockBind(Arc::new(callback)));
// }
// pub fn blockable_bind<F: Fn(Event) -> BlockInput + Send + Sync + 'static>(
// listen_type: EventListenType,
// callback: F,
// ) {
// EVENT_BINDS
// .lock()
// .unwrap()
// .insert(listen_type, Bind::BlockableBind(Arc::new(callback)));
// }
// pub fn unbind(listen_type: EventListenType) {
// EVENT_BINDS.lock().unwrap().remove(&listen_type);
// }
// }