keyflow 0.1.0

Cross-platform input simulation library for keyboard, mouse and hotkeys.
Documentation
use crate::error::Result;
use crate::keyflow::Keyflow;
use crate::types::Screen;

/// KeyflowBuilder configures the API
pub struct KeyflowBuilder {
    pub(crate) enable_hotkeys: bool,
    pub(crate) screen: Option<Screen>,
}

impl Default for KeyflowBuilder {
    fn default() -> Self {
        Self::new()
    }
}

impl KeyflowBuilder {
    pub fn new() -> Self {
        Self {
            enable_hotkeys: false,
            screen: None,
        }
    }

    /// Enable hotkeys
    pub fn with_hotkeys(mut self) -> Self {
        self.enable_hotkeys = true;
        self
    }

    /// Define screen limits
    pub fn with_screen(mut self, screen: Screen) -> Self {
        self.screen = Some(screen);
        self
    }

    /// Initialize the underlying event handler.
    ///
    /// # Errors
    ///
    /// Returns error if already initialized, device / eventhandler creation failed
    /// or if the [Screen](self.with_screen) is missing if compiled for linux.
    pub fn initialize(self) -> Result<()> {
        Keyflow::initialize_with_config(self)
    }
}

impl Keyflow {
    /// Create a builder for custom initialization
    ///
    /// # Example
    ///
    /// ```no_run
    /// use keyflow::prelude::*;
    ///
    /// Keyflow::builder()
    ///     .with_hotkeys()
    ///     .with_screen(Screen::new(0, 0, 1920, 1080))
    ///     .initialize()?;
    ///
    /// # Ok(())
    /// ```
    pub fn builder() -> KeyflowBuilder {
        KeyflowBuilder::new()
    }
}