keyflow 0.1.0

Cross-platform input simulation library for keyboard, mouse and hotkeys.
Documentation
use crate::error::Result;
use crate::hotkey::{HotkeyListener, HotkeyRegistry};
use crate::types::*;
use std::sync::{Arc, RwLock};

pub(crate) trait Simulation: Send {
    /// Send a key
    fn send_key(&mut self, key: Key, action: Action) -> Result<()>;
    /// Send a mouse button
    fn send_button(&mut self, button: Button, action: Action) -> Result<()>;
    /// Send mouse movement
    fn send_movement(&mut self, movement: Movement) -> Result<()>;
    /// Send scroll
    fn send_scroll(&mut self, scroll: Scroll) -> Result<()>;
    /// Send a batch of [`InputEvent`]s
    fn send_batch(&mut self, batch: Vec<InputEvent>) -> Result<()>;
}

pub struct BackendListener {
    listener: Arc<HotkeyListener>,
}

impl BackendListener {
    pub(crate) fn new(registry: Arc<RwLock<HotkeyRegistry>>) -> Self {
        Self {
            listener: Arc::new(HotkeyListener::new(registry)),
        }
    }
}

pub(crate) trait Listener: Send + Sync {
    /// Start to listen to hotkeys
    fn start(&self) -> Result<()>;
    /// Stop listen
    fn stop(&self);
}

#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
pub(crate) use linux::Backend;

#[cfg(target_os = "windows")]
mod windows;
#[cfg(target_os = "windows")]
pub(crate) use windows::Backend;