[
  {
    "path": ".gitignore",
    "content": "# IDEs auto-generated files\n.idea\n\n# Cargo files\n/target/\n**/*.rs.bk\nCargo.lock\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: rust\ncache: cargo\nmatrix:\n  include:\n    - os: linux\n      rust: stable\n      env: TARGET=x86_64_unknown_linux_gnu\n    - os: linux\n      rust: nightly\n      env: TARGET=x86_64_unknown_linux_gnu\n\n"
  },
  {
    "path": "Cargo.toml",
    "content": "[package]\nname = \"device_query\"\nversion = \"4.0.1\"\nauthors = [\"ostrosco <ostrosco@fastmail.fm>\"]\nbuild = \"build.rs\"\ndescription = \"A basic library for querying keyboard and mouse state on-demand without a window.\"\nhomepage = \"https://github.com/ostrosco/device_query\"\nrepository = \"https://github.com/ostrosco/device_query\"\nreadme = \"README.md\"\nkeywords = [\"input\", \"mouse\", \"keyboard\"]\nlicense = \"MIT\"\n\n[badges]\ntravis-ci = { repository = \"ostrosco/device_query\" }\n\n[build-dependencies]\npkg-config = \"0.3.26\"\n\n[dependencies]\n\n[target.'cfg(target_os = \"linux\")'.dependencies]\nx11 = {version = \"2.21.0\", features = [\"xlib\"] }\n\n[target.'cfg(target_os = \"windows\")'.dependencies]\nwindows = {version = \"0.48.0\", features = [\"Win32_UI_Input_KeyboardAndMouse\", \"Win32_UI_WindowsAndMessaging\", \"Win32_Foundation\", \"Win32_Foundation\"]}\n\n[target.'cfg(target_os = \"macos\")'.dependencies]\nreadkey = \"0.2.2\"\nreadmouse = \"0.2.1\"\nmacos-accessibility-client = \"0.0.1\"\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2018 ostrosco\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# device_query\n\n# NOTE: This repository has been relocated to https://codeberg.org/ostrosco/device_query. Future work will continue there.\n\n[![Build Status](https://travis-ci.org/ostrosco/device_query.svg?branch=master)](https://travis-ci.org/ostrosco/device_query)\n\nA simple library to query mouse and keyboard inputs on demand without a window.\nWill work in Windows, Linux on X11, and macOS.\n\n```Rust\nuse device_query::{DeviceQuery, DeviceState, MouseState, Keycode};\n\nlet device_state = DeviceState::new();\nlet mouse: MouseState = device_state.get_mouse();\nprintln!(\"Current Mouse Coordinates: {:?}\", mouse.coords);\nlet keys: Vec<Keycode> = device_state.get_keys();\nprintln!(\"Is A pressed? {}\", keys.contains(Keycode::A));\n```\n\n# Dependencies\n\nWindows shouldn't require any special software to be installed for `device_query` to work properly.\nOn Linux, the X11 development libraries are required for `device_query` to query state from the OS.\n\nOn Ubuntu/Debian:\n```\nsudo apt install libx11-dev\n```\n\nOn Fedora/RHEL/CentOS:\n```\nsudo dnf install xorg-x11-server-devel\n```\n\nOn newer versions of MacOS, you may run into issues where you only see meta keys such as shift,\nbackspace, et cetera. This is due to a permission issue. To work around this:\n\n* open the MacOS system preferences\n* go to Security -> Privacy\n* scroll down to Accessibility and unlock it\n* add the app that is using `device_query` (such as your terminal) to the list\n\n# Device Callbacks\n\n`device_query` allows you to register callbacks for various device events such as key presses and mouse movements.\n\n## Example\n\nHere's a simple example demonstrating how to use the callback system:\n\n```rust\nextern crate device_query;\nuse device_query::{DeviceEvents, DeviceEventsHandler, Keycode, MouseButton, MousePosition};\nuse std::thread;\nuse std::time::Duration;\n\nfn main() {\n    // Initialize the event handler with a sleep duration of 10 milliseconds\n    let event_handler = DeviceEventsHandler::new(Duration::from_millis(10))\n        .expect(\"Could not initialize event loop\");\n\n    // Register callbacks for various events\n    // The callbacks will be automatically deregistered when they go out of scope\n    let _mouse_move_guard = event_handler.on_mouse_move(|position: &MousePosition| {\n        println!(\"Mouse moved to position: {:?}\", position);\n    });\n\n    // Keep the main thread alive to continue receiving events\n    loop {\n        thread::sleep(Duration::from_secs(1000));\n    }\n}\n```\n"
  },
  {
    "path": "build.rs",
    "content": "extern crate pkg_config;\n\n#[cfg(target_os = \"windows\")]\nfn main() {}\n\n#[cfg(target_os = \"macos\")]\nfn main() {}\n\n#[cfg(target_os = \"linux\")]\nuse std::env;\n#[cfg(target_os = \"linux\")]\nuse std::fs::File;\n#[cfg(target_os = \"linux\")]\nuse std::io::Write;\n#[cfg(target_os = \"linux\")]\nuse std::path::Path;\n\n#[cfg(target_os = \"linux\")]\nfn main() {\n    let mut config = String::new();\n    let libdir = match pkg_config::get_variable(\"x11\", \"libdir\") {\n        Ok(libdir) => format!(\"Some(\\\"{}\\\")\", libdir),\n        Err(_) => \"None\".to_string(),\n    };\n    config.push_str(&format!(\n        \"pub const {}: Option<&'static str> = {};\\n\",\n        \"x11\", libdir\n    ));\n\n    let config = format!(\"pub mod config {{ pub mod libdir {{\\n{}}}\\n}}\", config);\n    let out_dir = env::var(\"OUT_DIR\").unwrap();\n    let dest_path = Path::new(&out_dir).join(\"config.rs\");\n    let mut f = File::create(dest_path).unwrap();\n    f.write_all(&config.into_bytes()).unwrap();\n\n    let target = env::var(\"TARGET\").unwrap();\n    if target.contains(\"linux\") {\n        println!(\"cargo:rustc-link-lib=dl\");\n    } else if target.contains(\"freebsd\") || target.contains(\"dragonfly\") {\n        println!(\"cargo:rustc-link-lib=c\");\n    }\n}\n"
  },
  {
    "path": "examples/event_based_print_keys.rs",
    "content": "extern crate device_query;\n\nuse device_query::{DeviceEvents, DeviceEventsHandler};\nuse std::thread;\nuse std::time::Duration;\n\nfn main() {\n    let event_handler = DeviceEventsHandler::new(Duration::from_millis(10))\n        .expect(\"Could not initialize event loop\");\n    let _guard = event_handler.on_key_down(|key| {\n        println!(\"Down: {:#?}\", key);\n    });\n    let _guard = event_handler.on_key_up(|key| {\n        println!(\"Up: {:#?}\", key);\n    });\n\n    loop {\n        thread::sleep(Duration::from_secs(1000));\n    }\n}\n"
  },
  {
    "path": "examples/event_based_print_mouse.rs",
    "content": "extern crate device_query;\n\nuse device_query::{DeviceEvents, DeviceEventsHandler};\nuse std::thread;\nuse std::time::Duration;\n\nfn main() {\n    let event_handler = DeviceEventsHandler::new(std::time::Duration::from_millis(10))\n        .expect(\"Could not initialize event loop\");\n    let _guard = event_handler.on_mouse_move(|position| {\n        println!(\"Position: {:#?}\", position);\n    });\n    let _guard = event_handler.on_mouse_down(|button| {\n        println!(\"Down: {:#?}\", button);\n    });\n    let _guard = event_handler.on_mouse_up(|button| {\n        println!(\"Up: {:#?}\", button);\n    });\n\n    loop {\n        thread::sleep(Duration::from_secs(1000));\n    }\n}\n"
  },
  {
    "path": "examples/print_keys.rs",
    "content": "extern crate device_query;\n\nuse device_query::{DeviceQuery, DeviceState};\n\nfn main() {\n    let device_state = DeviceState::new();\n    let mut prev_keys = vec![];\n    loop {\n        let keys = device_state.get_keys();\n        if keys != prev_keys {\n            println!(\"{:?}\", keys);\n        }\n        prev_keys = keys;\n    }\n}\n"
  },
  {
    "path": "examples/print_mouse.rs",
    "content": "extern crate device_query;\n\nuse device_query::{DeviceQuery, DeviceState, MouseState};\n\nfn main() {\n    let device_state = DeviceState::new();\n    let mut prev_mouse = MouseState::default();\n    loop {\n        let mouse = device_state.get_mouse();\n        if mouse != prev_mouse {\n            println!(\"{:?}\", mouse);\n        }\n        prev_mouse = mouse;\n    }\n}\n"
  },
  {
    "path": "src/device_events/callback/callback_guard.rs",
    "content": "//! Callback guard.\n\nuse std::sync::Arc;\n\n/// Callback guard returned when adding a callback as an event listener. If the guard is dropped,\n/// the event listener is removed.\n#[derive(Debug)]\npub struct CallbackGuard<Callback> {\n    pub(crate) _callback: Arc<Callback>,\n}\n"
  },
  {
    "path": "src/device_events/callback/keyboard_callback.rs",
    "content": "use crate::device_events::utils;\nuse std::ops::DerefMut;\nuse std::sync::{Arc, Mutex, Weak};\nuse Keycode;\n\n/// Keyboard callback.\npub type KeyboardCallback = dyn Fn(&Keycode) + Sync + Send + 'static;\n\n/// Keyboard callbacks.\n#[derive(Default)]\npub(crate) struct KeyboardCallbacks {\n    key_down: Mutex<Vec<Weak<KeyboardCallback>>>,\n    key_up: Mutex<Vec<Weak<KeyboardCallback>>>,\n}\n\nimpl KeyboardCallbacks {\n    pub fn push_key_up(&self, callback: Arc<KeyboardCallback>) {\n        if let Ok(mut key_down) = self.key_up.lock() {\n            let callback = Arc::downgrade(&callback);\n            key_down.push(callback)\n        }\n    }\n\n    pub fn push_key_down(&self, callback: Arc<KeyboardCallback>) {\n        if let Ok(mut key_down) = self.key_down.lock() {\n            let callback = Arc::downgrade(&callback);\n            key_down.push(callback)\n        }\n    }\n\n    pub fn run_key_up(&self, key: &Keycode) {\n        if let Ok(mut callbacks) = self.key_up.lock() {\n            utils::DrainFilter::drain_filter(callbacks.deref_mut(), |callback| {\n                callback.upgrade().is_none()\n            });\n            for callback in callbacks.iter() {\n                if let Some(callback) = callback.upgrade() {\n                    callback(key);\n                }\n            }\n        }\n    }\n\n    pub fn run_key_down(&self, key: &Keycode) {\n        if let Ok(mut callbacks) = self.key_down.lock() {\n            utils::DrainFilter::drain_filter(callbacks.deref_mut(), |callback| {\n                callback.upgrade().is_none()\n            });\n            for callback in callbacks.iter() {\n                if let Some(callback) = callback.upgrade() {\n                    callback(key);\n                }\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "src/device_events/callback/mod.rs",
    "content": "mod callback_guard;\nmod keyboard_callback;\nmod mouse_callback;\n\npub use self::callback_guard::*;\npub use self::keyboard_callback::*;\npub use self::mouse_callback::*;\n"
  },
  {
    "path": "src/device_events/callback/mouse_callback.rs",
    "content": "//! Mouse callback.\n\nuse crate::device_events::utils;\nuse std::ops::DerefMut;\nuse std::sync::{Arc, Mutex, Weak};\nuse MouseButton;\nuse MousePosition;\n\n/// Mouse move callback.\npub type MouseMoveCallback = dyn Fn(&MousePosition) + Sync + Send + 'static;\n\n/// Mouse button callback.\npub type MouseButtonCallback = dyn Fn(&MouseButton) + Sync + Send + 'static;\n\n/// Mouse callbacks.\n#[derive(Default)]\npub(crate) struct MouseCallbacks {\n    pub mouse_move: Mutex<Vec<Weak<MouseMoveCallback>>>,\n    pub mouse_up: Mutex<Vec<Weak<MouseButtonCallback>>>,\n    pub mouse_down: Mutex<Vec<Weak<MouseButtonCallback>>>,\n}\n\nimpl MouseCallbacks {\n    pub fn push_mouse_move(&self, callback: Arc<MouseMoveCallback>) {\n        if let Ok(mut callbacks) = self.mouse_move.lock() {\n            let callback = Arc::downgrade(&callback);\n            callbacks.push(callback)\n        }\n    }\n\n    pub fn push_mouse_down(&self, callback: Arc<MouseButtonCallback>) {\n        if let Ok(mut callbacks) = self.mouse_down.lock() {\n            let callback = Arc::downgrade(&callback);\n            callbacks.push(callback)\n        }\n    }\n\n    pub fn push_mouse_up(&self, callback: Arc<MouseButtonCallback>) {\n        if let Ok(mut callbacks) = self.mouse_up.lock() {\n            let callback = Arc::downgrade(&callback);\n            callbacks.push(callback)\n        }\n    }\n\n    pub fn run_mouse_move(&self, position: &MousePosition) {\n        if let Ok(mut callbacks) = self.mouse_move.lock() {\n            utils::DrainFilter::drain_filter(callbacks.deref_mut(), |callback| {\n                callback.upgrade().is_none()\n            });\n            for callback in callbacks.iter() {\n                if let Some(callback) = callback.upgrade() {\n                    callback(position);\n                }\n            }\n        }\n    }\n\n    pub fn run_mouse_down(&self, button: &MouseButton) {\n        if let Ok(mut callbacks) = self.mouse_down.lock() {\n            utils::DrainFilter::drain_filter(callbacks.deref_mut(), |callback| {\n                callback.upgrade().is_none()\n            });\n            for callback in callbacks.iter() {\n                if let Some(callback) = callback.upgrade() {\n                    callback(button);\n                }\n            }\n        }\n    }\n\n    pub fn run_mouse_up(&self, button: &MouseButton) {\n        if let Ok(mut callbacks) = self.mouse_up.lock() {\n            utils::DrainFilter::drain_filter(callbacks.deref_mut(), |callback| {\n                callback.upgrade().is_none()\n            });\n            for callback in callbacks.iter() {\n                if let Some(callback) = callback.upgrade() {\n                    callback(button);\n                }\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "src/device_events/event_loop.rs",
    "content": "use super::{CallbackGuard, KeyboardCallbacks};\nuse std::sync::{Arc, LazyLock, Mutex, Weak};\nuse std::thread::{sleep, spawn, JoinHandle};\nuse std::time::Duration;\nuse MouseState;\nuse {DeviceQuery, MouseCallbacks};\nuse {DeviceState, Keycode};\nuse {MouseButton, MousePosition};\n\npub(crate) struct EventLoop {\n    keyboard_callbacks: Arc<KeyboardCallbacks>,\n    mouse_callbacks: Arc<MouseCallbacks>,\n    _keyboard_thread: JoinHandle<()>,\n    _mouse_thread: JoinHandle<()>,\n}\n\nfn keyboard_thread(callbacks: Weak<KeyboardCallbacks>, sleep_dur: Duration) -> JoinHandle<()> {\n    spawn(move || {\n        let device_state = DeviceState::new();\n        let mut prev_keys = vec![];\n        while let Some(callbacks) = callbacks.upgrade() {\n            let keys = device_state.get_keys();\n            for key_state in &keys {\n                if !prev_keys.contains(key_state) {\n                    callbacks.run_key_down(key_state);\n                }\n            }\n            for key_state in &prev_keys {\n                if !keys.contains(key_state) {\n                    callbacks.run_key_up(key_state);\n                }\n            }\n            prev_keys = keys;\n            sleep(sleep_dur);\n        }\n    })\n}\n\nfn mouse_thread(callbacks: Weak<MouseCallbacks>, sleep_dur: Duration) -> JoinHandle<()> {\n    spawn(move || {\n        let device_state = DeviceState::new();\n        let mut previous_mouse_state = MouseState::default();\n        while let Some(callbacks) = callbacks.upgrade() {\n            let mouse_state = device_state.get_mouse();\n            for (index, (previous_state, current_state)) in previous_mouse_state\n                .button_pressed\n                .iter()\n                .zip(mouse_state.button_pressed.iter())\n                .enumerate()\n            {\n                if !(*previous_state) && *current_state {\n                    callbacks.run_mouse_down(&index);\n                } else if *previous_state && !(*current_state) {\n                    callbacks.run_mouse_up(&index);\n                }\n            }\n            if mouse_state.coords != previous_mouse_state.coords {\n                callbacks.run_mouse_move(&mouse_state.coords);\n            }\n            previous_mouse_state = mouse_state;\n            sleep(sleep_dur);\n        }\n    })\n}\n\nimpl Default for EventLoop {\n    fn default() -> Self {\n        Self::new(Duration::from_micros(100))\n    }\n}\n\nimpl EventLoop {\n    fn new(sleep_dur: Duration) -> Self {\n        let keyboard_callbacks = Arc::new(KeyboardCallbacks::default());\n        let mouse_callbacks = Arc::new(MouseCallbacks::default());\n        let _keyboard_thread = keyboard_thread(Arc::downgrade(&keyboard_callbacks), sleep_dur);\n        let _mouse_thread = mouse_thread(Arc::downgrade(&mouse_callbacks), sleep_dur);\n        Self {\n            keyboard_callbacks,\n            mouse_callbacks,\n            _keyboard_thread,\n            _mouse_thread,\n        }\n    }\n\n    pub fn on_key_down<Callback: Fn(&Keycode) + Send + Sync + 'static>(\n        &mut self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback> {\n        let _callback = Arc::new(callback);\n        self.keyboard_callbacks.push_key_down(_callback.clone());\n        CallbackGuard { _callback }\n    }\n\n    pub fn on_key_up<Callback: Fn(&Keycode) + Send + Sync + 'static>(\n        &mut self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback> {\n        let _callback = Arc::new(callback);\n        self.keyboard_callbacks.push_key_up(_callback.clone());\n        CallbackGuard { _callback }\n    }\n\n    pub fn on_mouse_move<Callback: Fn(&MousePosition) + Send + Sync + 'static>(\n        &mut self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback> {\n        let _callback = Arc::new(callback);\n        self.mouse_callbacks.push_mouse_move(_callback.clone());\n        CallbackGuard { _callback }\n    }\n\n    pub fn on_mouse_up<Callback: Fn(&MouseButton) + Send + Sync + 'static>(\n        &mut self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback> {\n        let _callback = Arc::new(callback);\n        self.mouse_callbacks.push_mouse_up(_callback.clone());\n        CallbackGuard { _callback }\n    }\n\n    pub fn on_mouse_down<Callback: Fn(&MouseButton) + Send + Sync + 'static>(\n        &mut self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback> {\n        let _callback = Arc::new(callback);\n        self.mouse_callbacks.push_mouse_down(_callback.clone());\n        CallbackGuard { _callback }\n    }\n}\n\npub(crate) static EVENT_LOOP: LazyLock<Mutex<Option<EventLoop>>> = LazyLock::new(|| Default::default());\n\npub(crate) fn init_event_loop(sleep_dur: Duration) -> bool {\n    let Ok(mut lock) = EVENT_LOOP.lock() else {\n        return false;\n    };\n    if lock.is_some() {\n        return false;\n    }\n    *lock = Some(EventLoop::new(sleep_dur));\n    true\n}"
  },
  {
    "path": "src/device_events/mod.rs",
    "content": "//! Devices events listeners.\n//! \n//! This module contains the implementation of the DeviceEventsHandler struct.\n//! This allows to register callbacks for device events.\n//! for the current state of the device, see the [`DeviceState`](crate::device_state::DeviceState) struct.\n//! \n//! # Example\n//! \n//! ```no_run\n//! use device_query::{DeviceEvents, DeviceEventsHandler, Keycode, MouseButton};\n//! use std::time::Duration;\n//! \n//! fn main() {\n//!   let device_events = DeviceEventsHandler::new(Duration::from_millis(10)).unwrap();\n//!   // Register a key down event callback\n//!   // The guard is used to keep the callback alive\n//!   let _guard = device_events.on_key_down(|key| {\n//!     println!(\"Key down: {:?}\", key);\n//!   });\n//!   // Keep the main thread alive\n//!   loop {}\n//! }\n//! \n//! ```\n//! \n\nmod callback;\nmod event_loop;\nmod utils;\n\nuse std::time::Duration;\n\nuse crate::MousePosition;\n\npub use self::callback::*;\nuse self::event_loop::*;\n\nuse Keycode;\nuse MouseButton;\n\n/// All the supported devices events.\npub trait DeviceEvents {\n    /// Register an on key down event callback.\n    fn on_key_down<Callback: Fn(&Keycode) + Sync + Send + 'static>(\n        &self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback>;\n    /// Register an on key up event callback.\n    fn on_key_up<Callback: Fn(&Keycode) + Sync + Send + 'static>(\n        &self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback>;\n\n    /// Register an on mouse move event callback.\n    fn on_mouse_move<Callback: Fn(&MousePosition) + Sync + Send + 'static>(\n        &self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback>;\n    /// Register an on mouse button down event callback.\n    fn on_mouse_down<Callback: Fn(&MouseButton) + Sync + Send + 'static>(\n        &self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback>;\n    /// Register an on mouse button up event callback.\n    fn on_mouse_up<Callback: Fn(&MouseButton) + Sync + Send + 'static>(\n        &self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback>;\n}\n\npub struct DeviceEventsHandler;\n\nimpl DeviceEventsHandler {\n    /// Attempts to start event loop with the given sleep duration.\n    /// Returns None if the event loop is already running.\n    pub fn new(sleep_dur: Duration) -> Option<Self> {\n        event_loop::init_event_loop(sleep_dur).then_some(DeviceEventsHandler)\n    }\n}\n\n/// Returns the event loop.\n///\n/// This is a workaround to avoid using unsafe code,\n/// the existence of a [`DeviceEventsHandler`] means that the event loop is already initialized.\nmacro_rules! get_event_loop {\n    () => {\n        EVENT_LOOP\n            .lock()\n            .expect(\"Couldn't lock EVENT_LOOP\")\n            .as_mut()\n            .unwrap()\n    };\n}\n\nimpl DeviceEvents for DeviceEventsHandler {\n    fn on_key_down<Callback: Fn(&Keycode) + Sync + Send + 'static>(\n        &self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback> {\n        get_event_loop!().on_key_down(callback)\n    }\n\n    fn on_key_up<Callback: Fn(&Keycode) + Sync + Send + 'static>(\n        &self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback> {\n        get_event_loop!().on_key_up(callback)\n    }\n\n    fn on_mouse_move<Callback: Fn(&MousePosition) + Sync + Send + 'static>(\n        &self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback> {\n        get_event_loop!().on_mouse_move(callback)\n    }\n\n    fn on_mouse_down<Callback: Fn(&MouseButton) + Sync + Send + 'static>(\n        &self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback> {\n        get_event_loop!().on_mouse_down(callback)\n    }\n\n    fn on_mouse_up<Callback: Fn(&MouseButton) + Sync + Send + 'static>(\n        &self,\n        callback: Callback,\n    ) -> CallbackGuard<Callback> {\n        get_event_loop!().on_mouse_up(callback)\n    }\n}\n"
  },
  {
    "path": "src/device_events/utils.rs",
    "content": "//! Utils.\n\n/// This is a placeholder for the unstable feature.\npub trait DrainFilter<T> {\n    fn drain_filter<F>(&mut self, filter: F)\n    where\n        F: FnMut(&mut T) -> bool;\n}\n\nimpl<T> DrainFilter<T> for Vec<T> {\n    fn drain_filter<F>(&mut self, filter: F)\n    where\n        F: FnMut(&mut T) -> bool,\n    {\n        let mut filter = filter;\n        if self.is_empty() {\n            return;\n        }\n\n        let mut i = self.len();\n        while i > 0 {\n            i -= 1;\n            if filter(&mut self[i]) {\n                self.remove(i);\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "src/device_query.rs",
    "content": "//! Query functions.\n\nuse DeviceState;\nuse {Keycode, MouseState};\n\n/// Trait to get the state of the supported devices.\npub trait DeviceQuery {\n    /// Get MouseState.\n    fn get_mouse(&self) -> MouseState;\n\n    /// Get Keyboard state.\n    fn get_keys(&self) -> Vec<Keycode>;\n}\n\nimpl DeviceQuery for DeviceState {\n    /// Query for the current mouse position and mouse button device_state.\n    fn get_mouse(&self) -> MouseState {\n        self.query_pointer()\n    }\n\n    /// Query for all keys that are currently pressed down.\n    fn get_keys(&self) -> Vec<Keycode> {\n        self.query_keymap()\n    }\n}\n"
  },
  {
    "path": "src/device_state/linux/kernel_key.rs",
    "content": "/// A non-exhaustive list of keycodes from Linux. Only the ones that this library currently supports\n/// is currently listed in this file; other keycodes will need to be added later as needed.\n/// Reference: https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h\n\npub const KEY_ESC: u16 = 1;\npub const KEY_1: u16 = 2;\npub const KEY_2: u16 = 3;\npub const KEY_3: u16 = 4;\npub const KEY_4: u16 = 5;\npub const KEY_5: u16 = 6;\npub const KEY_6: u16 = 7;\npub const KEY_7: u16 = 8;\npub const KEY_8: u16 = 9;\npub const KEY_9: u16 = 10;\npub const KEY_0: u16 = 11;\npub const KEY_MINUS: u16 = 12;\npub const KEY_EQUAL: u16 = 13;\npub const KEY_BACKSPACE: u16 = 14;\npub const KEY_TAB: u16 = 15;\npub const KEY_Q: u16 = 16;\npub const KEY_W: u16 = 17;\npub const KEY_E: u16 = 18;\npub const KEY_R: u16 = 19;\npub const KEY_T: u16 = 20;\npub const KEY_Y: u16 = 21;\npub const KEY_U: u16 = 22;\npub const KEY_I: u16 = 23;\npub const KEY_O: u16 = 24;\npub const KEY_P: u16 = 25;\npub const KEY_LEFTBRACE: u16 = 26;\npub const KEY_RIGHTBRACE: u16 = 27;\npub const KEY_ENTER: u16 = 28;\npub const KEY_LEFTCTRL: u16 = 29;\npub const KEY_A: u16 = 30;\npub const KEY_S: u16 = 31;\npub const KEY_D: u16 = 32;\npub const KEY_F: u16 = 33;\npub const KEY_G: u16 = 34;\npub const KEY_H: u16 = 35;\npub const KEY_J: u16 = 36;\npub const KEY_K: u16 = 37;\npub const KEY_L: u16 = 38;\npub const KEY_SEMICOLON: u16 = 39;\npub const KEY_APOSTROPHE: u16 = 40;\npub const KEY_GRAVE: u16 = 41;\npub const KEY_LEFTSHIFT: u16 = 42;\npub const KEY_BACKSLASH: u16 = 43;\npub const KEY_Z: u16 = 44;\npub const KEY_X: u16 = 45;\npub const KEY_C: u16 = 46;\npub const KEY_V: u16 = 47;\npub const KEY_B: u16 = 48;\npub const KEY_N: u16 = 49;\npub const KEY_M: u16 = 50;\npub const KEY_COMMA: u16 = 51;\npub const KEY_DOT: u16 = 52;\npub const KEY_SLASH: u16 = 53;\npub const KEY_RIGHTSHIFT: u16 = 54;\npub const KEY_KPASTERISK: u16 = 55;\npub const KEY_LEFTALT: u16 = 56;\npub const KEY_SPACE: u16 = 57;\npub const KEY_CAPSLOCK: u16 = 58;\npub const KEY_F1: u16 = 59;\npub const KEY_F2: u16 = 60;\npub const KEY_F3: u16 = 61;\npub const KEY_F4: u16 = 62;\npub const KEY_F5: u16 = 63;\npub const KEY_F6: u16 = 64;\npub const KEY_F7: u16 = 65;\npub const KEY_F8: u16 = 66;\npub const KEY_F9: u16 = 67;\npub const KEY_F10: u16 = 68;\npub const KEY_KP7: u16 = 71;\npub const KEY_KP8: u16 = 72;\npub const KEY_KP9: u16 = 73;\npub const KEY_KPMINUS: u16 = 74;\npub const KEY_KP4: u16 = 75;\npub const KEY_KP5: u16 = 76;\npub const KEY_KP6: u16 = 77;\npub const KEY_KPPLUS: u16 = 78;\npub const KEY_KP1: u16 = 79;\npub const KEY_KP2: u16 = 80;\npub const KEY_KP3: u16 = 81;\npub const KEY_KP0: u16 = 82;\npub const KEY_KPDOT: u16 = 83;\npub const KEY_F11: u16 = 87;\npub const KEY_F12: u16 = 88;\npub const KEY_F13: u16 = 183;\npub const KEY_F14: u16 = 184;\npub const KEY_F15: u16 = 185;\npub const KEY_F16: u16 = 186;\npub const KEY_F17: u16 = 187;\npub const KEY_F18: u16 = 188;\npub const KEY_F19: u16 = 189;\npub const KEY_F20: u16 = 190;\npub const KEY_KPENTER: u16 = 96;\npub const KEY_RIGHTCTRL: u16 = 97;\npub const KEY_KPSLASH: u16 = 98;\npub const KEY_RIGHTALT: u16 = 100;\npub const KEY_HOME: u16 = 102;\npub const KEY_UP: u16 = 103;\npub const KEY_PAGEUP: u16 = 104;\npub const KEY_LEFT: u16 = 105;\npub const KEY_RIGHT: u16 = 106;\npub const KEY_END: u16 = 107;\npub const KEY_DOWN: u16 = 108;\npub const KEY_PAGEDOWN: u16 = 109;\npub const KEY_INSERT: u16 = 110;\npub const KEY_DELETE: u16 = 111;\npub const KEY_KPEQUAL: u16 = 117;\npub const KEY_LEFTMETA: u16 = 125;\npub const KEY_RIGHTMETA: u16 = 126;\n"
  },
  {
    "path": "src/device_state/linux/mod.rs",
    "content": "extern crate x11;\n\nuse self::x11::xlib;\nuse keymap::Keycode;\nuse mouse_state::MouseState;\nuse std::os::raw::c_char;\nuse std::ptr;\nuse std::rc::Rc;\nuse std::slice;\n\nmod kernel_key;\n\n#[derive(Debug, Clone)]\n/// Device state descriptor.\npub struct DeviceState {\n    xc: Rc<X11Connection>,\n}\n\n#[derive(Debug)]\nstruct X11Connection {\n    display: *mut xlib::Display,\n}\n\nimpl Drop for X11Connection {\n    fn drop(&mut self) {\n        unsafe {\n            xlib::XCloseDisplay(self.display);\n        }\n    }\n}\n\nimpl DeviceState {\n    /// Creates a new DeviceState.\n    pub fn new() -> DeviceState {\n        unsafe {\n            let display = xlib::XOpenDisplay(ptr::null());\n            if display.as_ref().is_none() {\n                panic!(\"Could not connect to a X display\");\n            }\n            DeviceState {\n                xc: Rc::new(X11Connection { display }),\n            }\n        }\n    }\n\n    /// Create a new DeviceState. In case of failure, doesn't panic.\n    pub fn checked_new() -> Option<DeviceState> {\n        unsafe {\n            let display = xlib::XOpenDisplay(ptr::null());\n            if display.as_ref().is_none() {\n                eprintln!(\"Could not connect to a X display\");\n                return None;\n            }\n            Some(DeviceState {\n                xc: Rc::new(X11Connection { display }),\n            })\n        }\n    }\n\n    /// Query the `MouseState`.\n    pub fn query_pointer(&self) -> MouseState {\n        let root;\n        let mut root_x = 0;\n        let mut root_y = 0;\n        let mut win_x = 0;\n        let mut win_y = 0;\n        let mut root_return = 0;\n        let mut child_return = 0;\n        let mut mask_return = 0;\n        unsafe {\n            root = xlib::XDefaultRootWindow(self.xc.display);\n            xlib::XQueryPointer(\n                self.xc.display,\n                root,\n                &mut root_return,\n                &mut child_return,\n                &mut root_x,\n                &mut root_y,\n                &mut win_x,\n                &mut win_y,\n                &mut mask_return,\n            );\n        }\n        let button1pressed = mask_return & xlib::Button1Mask > 0;\n        let button2pressed = mask_return & xlib::Button2Mask > 0;\n        let button3pressed = mask_return & xlib::Button3Mask > 0;\n        let button4pressed = mask_return & xlib::Button4Mask > 0;\n        let button5pressed = mask_return & xlib::Button5Mask > 0;\n\n        // Use 1-based indexing here so people can just query the button\n        // number they're interested in directly.\n        let button_pressed = vec![\n            false,\n            button1pressed,\n            button2pressed,\n            button3pressed,\n            button4pressed,\n            button5pressed,\n        ];\n        MouseState {\n            coords: (win_x, win_y),\n            button_pressed,\n        }\n    }\n\n    /// Query the Keyboard state.\n    pub fn query_keymap(&self) -> Vec<Keycode> {\n        let mut keycodes = vec![];\n        unsafe {\n            let keymap: *mut c_char = [0; 32].as_mut_ptr();\n            xlib::XQueryKeymap(self.xc.display, keymap);\n            for (ix, byte) in slice::from_raw_parts(keymap, 32).iter().enumerate() {\n                for bit in 0_u8..8_u8 {\n                    let bitmask = 1 << bit;\n                    if byte & bitmask != 0 {\n                        //x11 keycode uses kernel keycode with an offset of 8.\n                        let x11_key = ix as u8 * 8 + bit;\n                        let kernel_key = x11_key - 8;\n                        if let Some(k) = self.kernel_key_to_keycode(kernel_key) {\n                            keycodes.push(k)\n                        }\n                    }\n                }\n            }\n        }\n        keycodes\n    }\n\n    fn kernel_key_to_keycode(&self, kernel_code: u8) -> Option<Keycode> {\n        match kernel_code as u16 {\n            kernel_key::KEY_0 => Some(Keycode::Key0),\n            kernel_key::KEY_1 => Some(Keycode::Key1),\n            kernel_key::KEY_2 => Some(Keycode::Key2),\n            kernel_key::KEY_3 => Some(Keycode::Key3),\n            kernel_key::KEY_4 => Some(Keycode::Key4),\n            kernel_key::KEY_5 => Some(Keycode::Key5),\n            kernel_key::KEY_6 => Some(Keycode::Key6),\n            kernel_key::KEY_7 => Some(Keycode::Key7),\n            kernel_key::KEY_8 => Some(Keycode::Key8),\n            kernel_key::KEY_9 => Some(Keycode::Key9),\n            kernel_key::KEY_A => Some(Keycode::A),\n            kernel_key::KEY_B => Some(Keycode::B),\n            kernel_key::KEY_C => Some(Keycode::C),\n            kernel_key::KEY_D => Some(Keycode::D),\n            kernel_key::KEY_E => Some(Keycode::E),\n            kernel_key::KEY_F => Some(Keycode::F),\n            kernel_key::KEY_G => Some(Keycode::G),\n            kernel_key::KEY_H => Some(Keycode::H),\n            kernel_key::KEY_I => Some(Keycode::I),\n            kernel_key::KEY_J => Some(Keycode::J),\n            kernel_key::KEY_K => Some(Keycode::K),\n            kernel_key::KEY_L => Some(Keycode::L),\n            kernel_key::KEY_M => Some(Keycode::M),\n            kernel_key::KEY_N => Some(Keycode::N),\n            kernel_key::KEY_O => Some(Keycode::O),\n            kernel_key::KEY_P => Some(Keycode::P),\n            kernel_key::KEY_Q => Some(Keycode::Q),\n            kernel_key::KEY_R => Some(Keycode::R),\n            kernel_key::KEY_S => Some(Keycode::S),\n            kernel_key::KEY_T => Some(Keycode::T),\n            kernel_key::KEY_U => Some(Keycode::U),\n            kernel_key::KEY_V => Some(Keycode::V),\n            kernel_key::KEY_W => Some(Keycode::W),\n            kernel_key::KEY_X => Some(Keycode::X),\n            kernel_key::KEY_Y => Some(Keycode::Y),\n            kernel_key::KEY_Z => Some(Keycode::Z),\n            kernel_key::KEY_F1 => Some(Keycode::F1),\n            kernel_key::KEY_F2 => Some(Keycode::F2),\n            kernel_key::KEY_F3 => Some(Keycode::F3),\n            kernel_key::KEY_F4 => Some(Keycode::F4),\n            kernel_key::KEY_F5 => Some(Keycode::F5),\n            kernel_key::KEY_F6 => Some(Keycode::F6),\n            kernel_key::KEY_F7 => Some(Keycode::F7),\n            kernel_key::KEY_F8 => Some(Keycode::F8),\n            kernel_key::KEY_F9 => Some(Keycode::F9),\n            kernel_key::KEY_F10 => Some(Keycode::F10),\n            kernel_key::KEY_F11 => Some(Keycode::F11),\n            kernel_key::KEY_F12 => Some(Keycode::F12),\n            kernel_key::KEY_F13 => Some(Keycode::F13),\n            kernel_key::KEY_F14 => Some(Keycode::F14),\n            kernel_key::KEY_F15 => Some(Keycode::F15),\n            kernel_key::KEY_F16 => Some(Keycode::F16),\n            kernel_key::KEY_F17 => Some(Keycode::F17),\n            kernel_key::KEY_F18 => Some(Keycode::F18),\n            kernel_key::KEY_F19 => Some(Keycode::F19),\n            kernel_key::KEY_F20 => Some(Keycode::F20),\n            kernel_key::KEY_KP0 => Some(Keycode::Numpad0),\n            kernel_key::KEY_KP1 => Some(Keycode::Numpad1),\n            kernel_key::KEY_KP2 => Some(Keycode::Numpad2),\n            kernel_key::KEY_KP3 => Some(Keycode::Numpad3),\n            kernel_key::KEY_KP4 => Some(Keycode::Numpad4),\n            kernel_key::KEY_KP5 => Some(Keycode::Numpad5),\n            kernel_key::KEY_KP6 => Some(Keycode::Numpad6),\n            kernel_key::KEY_KP7 => Some(Keycode::Numpad7),\n            kernel_key::KEY_KP8 => Some(Keycode::Numpad8),\n            kernel_key::KEY_KP9 => Some(Keycode::Numpad9),\n            kernel_key::KEY_KPENTER => Some(Keycode::NumpadEnter),\n            kernel_key::KEY_KPMINUS => Some(Keycode::NumpadSubtract),\n            kernel_key::KEY_KPPLUS => Some(Keycode::NumpadAdd),\n            kernel_key::KEY_KPSLASH => Some(Keycode::NumpadDivide),\n            kernel_key::KEY_KPASTERISK => Some(Keycode::NumpadMultiply),\n            kernel_key::KEY_KPEQUAL => Some(Keycode::NumpadEquals),\n            kernel_key::KEY_KPDOT => Some(Keycode::NumpadDecimal),\n            kernel_key::KEY_ESC => Some(Keycode::Escape),\n            kernel_key::KEY_SPACE => Some(Keycode::Space),\n            kernel_key::KEY_LEFTCTRL => Some(Keycode::LControl),\n            kernel_key::KEY_RIGHTCTRL => Some(Keycode::RControl),\n            kernel_key::KEY_LEFTSHIFT => Some(Keycode::LShift),\n            kernel_key::KEY_RIGHTSHIFT => Some(Keycode::RShift),\n            kernel_key::KEY_LEFTALT => Some(Keycode::LAlt),\n            kernel_key::KEY_RIGHTALT => Some(Keycode::RAlt),\n            kernel_key::KEY_LEFTMETA => Some(Keycode::LMeta),\n            kernel_key::KEY_RIGHTMETA => Some(Keycode::RMeta),\n            kernel_key::KEY_ENTER => Some(Keycode::Enter),\n            kernel_key::KEY_UP => Some(Keycode::Up),\n            kernel_key::KEY_DOWN => Some(Keycode::Down),\n            kernel_key::KEY_LEFT => Some(Keycode::Left),\n            kernel_key::KEY_RIGHT => Some(Keycode::Right),\n            kernel_key::KEY_BACKSPACE => Some(Keycode::Backspace),\n            kernel_key::KEY_CAPSLOCK => Some(Keycode::CapsLock),\n            kernel_key::KEY_TAB => Some(Keycode::Tab),\n            kernel_key::KEY_HOME => Some(Keycode::Home),\n            kernel_key::KEY_END => Some(Keycode::End),\n            kernel_key::KEY_PAGEUP => Some(Keycode::PageUp),\n            kernel_key::KEY_PAGEDOWN => Some(Keycode::PageDown),\n            kernel_key::KEY_INSERT => Some(Keycode::Insert),\n            kernel_key::KEY_DELETE => Some(Keycode::Delete),\n            kernel_key::KEY_GRAVE => Some(Keycode::Grave),\n            kernel_key::KEY_MINUS => Some(Keycode::Minus),\n            kernel_key::KEY_EQUAL => Some(Keycode::Equal),\n            kernel_key::KEY_LEFTBRACE => Some(Keycode::LeftBracket),\n            kernel_key::KEY_RIGHTBRACE => Some(Keycode::RightBracket),\n            kernel_key::KEY_BACKSLASH => Some(Keycode::BackSlash),\n            kernel_key::KEY_SEMICOLON => Some(Keycode::Semicolon),\n            kernel_key::KEY_APOSTROPHE => Some(Keycode::Apostrophe),\n            kernel_key::KEY_COMMA => Some(Keycode::Comma),\n            kernel_key::KEY_DOT => Some(Keycode::Dot),\n            kernel_key::KEY_SLASH => Some(Keycode::Slash),\n            _ => None,\n        }\n    }\n}\n"
  },
  {
    "path": "src/device_state/macos/mod.rs",
    "content": "extern crate macos_accessibility_client;\n\nuse keymap::Keycode;\nuse mouse_state::MouseState;\n\n#[derive(Debug, Clone)]\npub struct DeviceState;\nconst MAPPING: &[(readkey::Keycode, Keycode)] = &[\n    (readkey::Keycode::_0, Keycode::Key0),\n    (readkey::Keycode::_1, Keycode::Key1),\n    (readkey::Keycode::_2, Keycode::Key2),\n    (readkey::Keycode::_3, Keycode::Key3),\n    (readkey::Keycode::_4, Keycode::Key4),\n    (readkey::Keycode::_5, Keycode::Key5),\n    (readkey::Keycode::_6, Keycode::Key6),\n    (readkey::Keycode::_7, Keycode::Key7),\n    (readkey::Keycode::_8, Keycode::Key8),\n    (readkey::Keycode::_9, Keycode::Key9),\n    (readkey::Keycode::A, Keycode::A),\n    (readkey::Keycode::B, Keycode::B),\n    (readkey::Keycode::C, Keycode::C),\n    (readkey::Keycode::D, Keycode::D),\n    (readkey::Keycode::E, Keycode::E),\n    (readkey::Keycode::F, Keycode::F),\n    (readkey::Keycode::G, Keycode::G),\n    (readkey::Keycode::H, Keycode::H),\n    (readkey::Keycode::I, Keycode::I),\n    (readkey::Keycode::J, Keycode::J),\n    (readkey::Keycode::K, Keycode::K),\n    (readkey::Keycode::L, Keycode::L),\n    (readkey::Keycode::M, Keycode::M),\n    (readkey::Keycode::N, Keycode::N),\n    (readkey::Keycode::O, Keycode::O),\n    (readkey::Keycode::P, Keycode::P),\n    (readkey::Keycode::Q, Keycode::Q),\n    (readkey::Keycode::R, Keycode::R),\n    (readkey::Keycode::S, Keycode::S),\n    (readkey::Keycode::T, Keycode::T),\n    (readkey::Keycode::U, Keycode::U),\n    (readkey::Keycode::V, Keycode::V),\n    (readkey::Keycode::W, Keycode::W),\n    (readkey::Keycode::X, Keycode::X),\n    (readkey::Keycode::Y, Keycode::Y),\n    (readkey::Keycode::Z, Keycode::Z),\n    (readkey::Keycode::F1, Keycode::F1),\n    (readkey::Keycode::F2, Keycode::F2),\n    (readkey::Keycode::F3, Keycode::F3),\n    (readkey::Keycode::F4, Keycode::F4),\n    (readkey::Keycode::F5, Keycode::F5),\n    (readkey::Keycode::F6, Keycode::F6),\n    (readkey::Keycode::F7, Keycode::F7),\n    (readkey::Keycode::F8, Keycode::F8),\n    (readkey::Keycode::F9, Keycode::F9),\n    (readkey::Keycode::F10, Keycode::F10),\n    (readkey::Keycode::F11, Keycode::F11),\n    (readkey::Keycode::F12, Keycode::F12),\n    (readkey::Keycode::F13, Keycode::F13),\n    (readkey::Keycode::F14, Keycode::F14),\n    (readkey::Keycode::F15, Keycode::F15),\n    (readkey::Keycode::F16, Keycode::F16),\n    (readkey::Keycode::F17, Keycode::F17),\n    (readkey::Keycode::F18, Keycode::F18),\n    (readkey::Keycode::F19, Keycode::F19),\n    (readkey::Keycode::F20, Keycode::F20),\n    (readkey::Keycode::Keypad0, Keycode::Numpad0),\n    (readkey::Keycode::Keypad1, Keycode::Numpad1),\n    (readkey::Keycode::Keypad2, Keycode::Numpad2),\n    (readkey::Keycode::Keypad3, Keycode::Numpad3),\n    (readkey::Keycode::Keypad4, Keycode::Numpad4),\n    (readkey::Keycode::Keypad5, Keycode::Numpad5),\n    (readkey::Keycode::Keypad6, Keycode::Numpad6),\n    (readkey::Keycode::Keypad7, Keycode::Numpad7),\n    (readkey::Keycode::Keypad8, Keycode::Numpad8),\n    (readkey::Keycode::Keypad9, Keycode::Numpad9),\n    (readkey::Keycode::KeypadPlus, Keycode::NumpadAdd),\n    (readkey::Keycode::KeypadMinus, Keycode::NumpadSubtract),\n    (readkey::Keycode::KeypadDivide, Keycode::NumpadDivide),\n    (readkey::Keycode::KeypadMultiply, Keycode::NumpadMultiply),\n    (readkey::Keycode::KeypadEquals, Keycode::NumpadEquals),\n    (readkey::Keycode::KeypadEnter, Keycode::NumpadEnter),\n    (readkey::Keycode::KeypadDecimal, Keycode::NumpadDecimal),\n    (readkey::Keycode::Escape, Keycode::Escape),\n    (readkey::Keycode::Space, Keycode::Space),\n    (readkey::Keycode::Control, Keycode::LControl),\n    (readkey::Keycode::RightControl, Keycode::RControl),\n    (readkey::Keycode::Shift, Keycode::LShift),\n    (readkey::Keycode::RightShift, Keycode::RShift),\n    (readkey::Keycode::Option, Keycode::LOption),\n    (readkey::Keycode::RightOption, Keycode::ROption),\n    (readkey::Keycode::Command, Keycode::Command),\n    (readkey::Keycode::RightCommand, Keycode::RCommand),\n    (readkey::Keycode::Return, Keycode::Enter),\n    (readkey::Keycode::Up, Keycode::Up),\n    (readkey::Keycode::Down, Keycode::Down),\n    (readkey::Keycode::Left, Keycode::Left),\n    (readkey::Keycode::Right, Keycode::Right),\n    (readkey::Keycode::Delete, Keycode::Backspace),\n    (readkey::Keycode::CapsLock, Keycode::CapsLock),\n    (readkey::Keycode::Tab, Keycode::Tab),\n    (readkey::Keycode::Home, Keycode::Home),\n    (readkey::Keycode::End, Keycode::End),\n    (readkey::Keycode::PageUp, Keycode::PageUp),\n    (readkey::Keycode::PageDown, Keycode::PageDown),\n    (readkey::Keycode::Help, Keycode::Insert),\n    (readkey::Keycode::ForwardDelete, Keycode::Delete),\n    (readkey::Keycode::Grave, Keycode::Grave),\n    (readkey::Keycode::Minus, Keycode::Minus),\n    (readkey::Keycode::Equal, Keycode::Equal),\n    (readkey::Keycode::LeftBracket, Keycode::LeftBracket),\n    (readkey::Keycode::RightBracket, Keycode::RightBracket),\n    (readkey::Keycode::Backslash, Keycode::BackSlash),\n    (readkey::Keycode::Semicolon, Keycode::Semicolon),\n    (readkey::Keycode::Quote, Keycode::Apostrophe),\n    (readkey::Keycode::Comma, Keycode::Comma),\n    (readkey::Keycode::Period, Keycode::Dot),\n    (readkey::Keycode::Slash, Keycode::Slash),\n];\n\nimpl DeviceState {\n    pub fn new() -> DeviceState {\n        // TODO: remove this\n        assert!(\n            has_accessibility(),\n            \"This app does not have Accessibility Permissions enabled and will not work\"\n        );\n\n        DeviceState {}\n    }\n\n    /// returns `None` if app doesn't accessibility permissions.\n    pub fn checked_new() -> Option<DeviceState> {\n        if has_accessibility() {\n            Some(DeviceState {})\n        } else {\n            None\n        }\n    }\n\n    pub fn query_pointer(&self) -> MouseState {\n        let (x, y) = readmouse::Mouse::location();\n        let button_pressed = vec![\n            false,\n            readmouse::Mouse::Left.is_pressed(),\n            readmouse::Mouse::Right.is_pressed(),\n            readmouse::Mouse::Center.is_pressed(),\n            false,\n        ];\n\n        MouseState {\n            coords: (x as i32, y as i32),\n            button_pressed,\n        }\n    }\n\n    pub fn query_keymap(&self) -> Vec<Keycode> {\n        MAPPING\n            .iter()\n            .filter(|(from, _)| from.is_pressed())\n            .map(|(_, to)| *to)\n            .collect()\n    }\n}\n\n/// Returns true if the Accessibility permissions necessary for this library to work are granted\n/// to this process\n///\n/// If this returns false, the app can request them through the OS APIs, or the user can:\n///   1. open the MacOS system preferences\n///   2. go to Security -> Privacy\n///   3. scroll down to Accessibility and unlock it\n///   4. Add the app that is using device_query (such as your terminal) to the list\n///\nfn has_accessibility() -> bool {\n    use self::macos_accessibility_client::accessibility::*;\n    // Without prompting:\n    // application_is_trusted()\n\n    // With prompting:\n    application_is_trusted_with_prompt()\n}\n"
  },
  {
    "path": "src/device_state/mod.rs",
    "content": "//! DeviceState implementation.\n//! \n//! This module contains the implementation of the DeviceState struct.\n//! This only allows to get the current state of the device.\n//! for callbacks, see the [`DeviceEventsHandler`](crate::device_events::DeviceEventsHandler) struct.\n//! \n//! # Example\n//! \n//! ```no_run\n//! use device_query::{DeviceState, DeviceQuery};\n//! \n//! fn main() {\n//!   let device_state = DeviceState::new(); \n//!   println!(\"Mouse position: {:?}\", device_state.get_mouse());\n//!   println!(\"Key down: {:?}\", device_state.get_keys());\n//! }\n//! \n//! ```\n\n#[cfg(target_os = \"linux\")]\nmod linux;\n#[cfg(target_os = \"linux\")]\npub use self::linux::DeviceState;\n\n#[cfg(target_os = \"windows\")]\nmod windows;\n#[cfg(target_os = \"windows\")]\npub use self::windows::DeviceState;\n\n#[cfg(target_os = \"macos\")]\nmod macos;\n#[cfg(target_os = \"macos\")]\npub use self::macos::DeviceState;\n\nimpl Default for DeviceState {\n    fn default() -> Self {\n        Self::new()\n    }\n}\n"
  },
  {
    "path": "src/device_state/windows/mod.rs",
    "content": "use keymap::Keycode;\nuse mouse_state::MouseState;\nuse windows::Win32::Foundation::POINT;\nuse windows::Win32::UI::Input::KeyboardAndMouse;\nuse windows::Win32::UI::Input::KeyboardAndMouse::{GetAsyncKeyState, VIRTUAL_KEY};\nuse windows::Win32::UI::WindowsAndMessaging::GetCursorPos;\n\n#[derive(Debug, Clone)]\npub struct DeviceState;\n\nimpl DeviceState {\n    pub fn new() -> Self {\n        Self {}\n    }\n\n    // Adding because Linux and OSX supports this where `new` can panic.\n    pub fn checked_new() -> Option<Self> {\n        Some(Self::new())\n    }\n\n    pub fn query_pointer(&self) -> MouseState {\n        let point = &mut POINT { x: 0, y: 0 };\n        let button1pressed;\n        let button2pressed;\n        let button3pressed;\n        let button4pressed;\n        let button5pressed;\n        let coords;\n        unsafe {\n            coords = if GetCursorPos(point).into() {\n                (point.x, point.y)\n            } else {\n                (0, 0)\n            };\n            button1pressed =\n                GetAsyncKeyState(KeyboardAndMouse::VK_LBUTTON.0 as i32) as u32 & 0x8000 != 0;\n            button2pressed =\n                GetAsyncKeyState(KeyboardAndMouse::VK_RBUTTON.0 as i32) as u32 & 0x8000 != 0;\n            button3pressed =\n                GetAsyncKeyState(KeyboardAndMouse::VK_MBUTTON.0 as i32) as u32 & 0x8000 != 0;\n            button4pressed =\n                GetAsyncKeyState(KeyboardAndMouse::VK_XBUTTON1.0 as i32) as u32 & 0x8000 != 0;\n            button5pressed =\n                GetAsyncKeyState(KeyboardAndMouse::VK_XBUTTON2.0 as i32) as u32 & 0x8000 != 0;\n        }\n        MouseState {\n            coords,\n            button_pressed: vec![\n                false,\n                button1pressed,\n                button2pressed,\n                button3pressed,\n                button4pressed,\n                button5pressed,\n            ],\n        }\n    }\n\n    pub fn query_keymap(&self) -> Vec<Keycode> {\n        let mut keycodes = vec![];\n        let mut keymap = vec![];\n        unsafe {\n            for key in 0..256 {\n                keymap.push(GetAsyncKeyState(key));\n            }\n        }\n        for (ix, byte) in keymap.iter().enumerate() {\n            if *byte as u32 & 0x8000 != 0 {\n                if let Some(k) = self.win_key_to_keycode(ix as u16) {\n                    keycodes.push(k)\n                }\n            }\n        }\n        keycodes\n    }\n\n    fn win_key_to_keycode(&self, win_key: u16) -> Option<Keycode> {\n        let mut keycode = match VIRTUAL_KEY(win_key) {\n            KeyboardAndMouse::VK_F1 => Some(Keycode::F1),\n            KeyboardAndMouse::VK_F2 => Some(Keycode::F2),\n            KeyboardAndMouse::VK_F3 => Some(Keycode::F3),\n            KeyboardAndMouse::VK_F4 => Some(Keycode::F4),\n            KeyboardAndMouse::VK_F5 => Some(Keycode::F5),\n            KeyboardAndMouse::VK_F6 => Some(Keycode::F6),\n            KeyboardAndMouse::VK_F7 => Some(Keycode::F7),\n            KeyboardAndMouse::VK_F8 => Some(Keycode::F8),\n            KeyboardAndMouse::VK_F9 => Some(Keycode::F9),\n            KeyboardAndMouse::VK_F10 => Some(Keycode::F10),\n            KeyboardAndMouse::VK_F11 => Some(Keycode::F11),\n            KeyboardAndMouse::VK_F12 => Some(Keycode::F12),\n            KeyboardAndMouse::VK_F13 => Some(Keycode::F13),\n            KeyboardAndMouse::VK_F14 => Some(Keycode::F14),\n            KeyboardAndMouse::VK_F15 => Some(Keycode::F15),\n            KeyboardAndMouse::VK_F16 => Some(Keycode::F16),\n            KeyboardAndMouse::VK_F17 => Some(Keycode::F17),\n            KeyboardAndMouse::VK_F18 => Some(Keycode::F18),\n            KeyboardAndMouse::VK_F19 => Some(Keycode::F19),\n            KeyboardAndMouse::VK_F20 => Some(Keycode::F20),\n            KeyboardAndMouse::VK_NUMPAD0 => Some(Keycode::Numpad0),\n            KeyboardAndMouse::VK_NUMPAD1 => Some(Keycode::Numpad1),\n            KeyboardAndMouse::VK_NUMPAD2 => Some(Keycode::Numpad2),\n            KeyboardAndMouse::VK_NUMPAD3 => Some(Keycode::Numpad3),\n            KeyboardAndMouse::VK_NUMPAD4 => Some(Keycode::Numpad4),\n            KeyboardAndMouse::VK_NUMPAD5 => Some(Keycode::Numpad5),\n            KeyboardAndMouse::VK_NUMPAD6 => Some(Keycode::Numpad6),\n            KeyboardAndMouse::VK_NUMPAD7 => Some(Keycode::Numpad7),\n            KeyboardAndMouse::VK_NUMPAD8 => Some(Keycode::Numpad8),\n            KeyboardAndMouse::VK_NUMPAD9 => Some(Keycode::Numpad9),\n            KeyboardAndMouse::VK_ADD => Some(Keycode::NumpadAdd),\n            KeyboardAndMouse::VK_SUBTRACT => Some(Keycode::NumpadSubtract),\n            KeyboardAndMouse::VK_DIVIDE => Some(Keycode::NumpadDivide),\n            KeyboardAndMouse::VK_MULTIPLY => Some(Keycode::NumpadMultiply),\n            KeyboardAndMouse::VK_OEM_NEC_EQUAL => Some(Keycode::NumpadEquals),\n            KeyboardAndMouse::VK_DECIMAL => Some(Keycode::NumpadDecimal),\n            KeyboardAndMouse::VK_SPACE => Some(Keycode::Space),\n            KeyboardAndMouse::VK_LCONTROL => Some(Keycode::LControl),\n            KeyboardAndMouse::VK_RCONTROL => Some(Keycode::RControl),\n            KeyboardAndMouse::VK_LSHIFT => Some(Keycode::LShift),\n            KeyboardAndMouse::VK_RSHIFT => Some(Keycode::RShift),\n            KeyboardAndMouse::VK_LMENU => Some(Keycode::LAlt),\n            KeyboardAndMouse::VK_RMENU => Some(Keycode::RAlt),\n            KeyboardAndMouse::VK_LWIN => Some(Keycode::LMeta),\n            KeyboardAndMouse::VK_RWIN => Some(Keycode::RMeta),\n            KeyboardAndMouse::VK_RETURN => Some(Keycode::Enter),\n            KeyboardAndMouse::VK_ESCAPE => Some(Keycode::Escape),\n            KeyboardAndMouse::VK_UP => Some(Keycode::Up),\n            KeyboardAndMouse::VK_DOWN => Some(Keycode::Down),\n            KeyboardAndMouse::VK_LEFT => Some(Keycode::Left),\n            KeyboardAndMouse::VK_RIGHT => Some(Keycode::Right),\n            KeyboardAndMouse::VK_BACK => Some(Keycode::Backspace),\n            KeyboardAndMouse::VK_CAPITAL => Some(Keycode::CapsLock),\n            KeyboardAndMouse::VK_TAB => Some(Keycode::Tab),\n            KeyboardAndMouse::VK_HOME => Some(Keycode::Home),\n            KeyboardAndMouse::VK_END => Some(Keycode::End),\n            KeyboardAndMouse::VK_PRIOR => Some(Keycode::PageUp),\n            KeyboardAndMouse::VK_NEXT => Some(Keycode::PageDown),\n            KeyboardAndMouse::VK_INSERT => Some(Keycode::Insert),\n            KeyboardAndMouse::VK_DELETE => Some(Keycode::Delete),\n            KeyboardAndMouse::VK_OEM_3 => Some(Keycode::Grave),\n            KeyboardAndMouse::VK_OEM_MINUS => Some(Keycode::Minus),\n            KeyboardAndMouse::VK_OEM_PLUS => Some(Keycode::Equal),\n            KeyboardAndMouse::VK_OEM_4 => Some(Keycode::LeftBracket),\n            KeyboardAndMouse::VK_OEM_6 => Some(Keycode::RightBracket),\n            KeyboardAndMouse::VK_OEM_5 => Some(Keycode::BackSlash),\n            KeyboardAndMouse::VK_OEM_1 => Some(Keycode::Semicolon),\n            KeyboardAndMouse::VK_OEM_7 => Some(Keycode::Apostrophe),\n            KeyboardAndMouse::VK_OEM_COMMA => Some(Keycode::Comma),\n            KeyboardAndMouse::VK_OEM_PERIOD => Some(Keycode::Dot),\n            KeyboardAndMouse::VK_OEM_2 => Some(Keycode::Slash),\n\n            _ => None,\n        };\n\n        if keycode.is_none() {\n            let win_key = win_key as u8;\n            keycode = match win_key as char {\n                '0' => Some(Keycode::Key0),\n                '1' => Some(Keycode::Key1),\n                '2' => Some(Keycode::Key2),\n                '3' => Some(Keycode::Key3),\n                '4' => Some(Keycode::Key4),\n                '5' => Some(Keycode::Key5),\n                '6' => Some(Keycode::Key6),\n                '7' => Some(Keycode::Key7),\n                '8' => Some(Keycode::Key8),\n                '9' => Some(Keycode::Key9),\n                'A' => Some(Keycode::A),\n                'B' => Some(Keycode::B),\n                'C' => Some(Keycode::C),\n                'D' => Some(Keycode::D),\n                'E' => Some(Keycode::E),\n                'F' => Some(Keycode::F),\n                'G' => Some(Keycode::G),\n                'H' => Some(Keycode::H),\n                'I' => Some(Keycode::I),\n                'J' => Some(Keycode::J),\n                'K' => Some(Keycode::K),\n                'L' => Some(Keycode::L),\n                'M' => Some(Keycode::M),\n                'N' => Some(Keycode::N),\n                'O' => Some(Keycode::O),\n                'P' => Some(Keycode::P),\n                'Q' => Some(Keycode::Q),\n                'R' => Some(Keycode::R),\n                'S' => Some(Keycode::S),\n                'T' => Some(Keycode::T),\n                'U' => Some(Keycode::U),\n                'V' => Some(Keycode::V),\n                'W' => Some(Keycode::W),\n                'X' => Some(Keycode::X),\n                'Y' => Some(Keycode::Y),\n                'Z' => Some(Keycode::Z),\n                _ => None,\n            }\n        }\n        keycode\n    }\n}\n"
  },
  {
    "path": "src/keymap.rs",
    "content": "//! List of keycodes.\n\nuse std::fmt;\nuse std::str::FromStr;\n\n/// A list of supported keys that we can query from the OS. Outside of mod.\n#[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]\n#[allow(missing_docs)]\npub enum Keycode {\n    Key0,\n    Key1,\n    Key2,\n    Key3,\n    Key4,\n    Key5,\n    Key6,\n    Key7,\n    Key8,\n    Key9,\n    A,\n    B,\n    C,\n    D,\n    E,\n    F,\n    G,\n    H,\n    I,\n    J,\n    K,\n    L,\n    M,\n    N,\n    O,\n    P,\n    Q,\n    R,\n    S,\n    T,\n    U,\n    V,\n    W,\n    X,\n    Y,\n    Z,\n    F1,\n    F2,\n    F3,\n    F4,\n    F5,\n    F6,\n    F7,\n    F8,\n    F9,\n    F10,\n    F11,\n    F12,\n    F13,\n    F14,\n    F15,\n    F16,\n    F17,\n    F18,\n    F19,\n    F20,\n    Escape,\n    Space,\n    LControl,\n    RControl,\n    LShift,\n    RShift,\n    LAlt,\n    RAlt,\n    // TODO rename `Command` into `RCommand` at new major release\n    Command,\n    RCommand,\n    LOption,\n    ROption,\n    LMeta,\n    RMeta,\n    Enter,\n    Up,\n    Down,\n    Left,\n    Right,\n    Backspace,\n    CapsLock,\n    Tab,\n    Home,\n    End,\n    PageUp,\n    PageDown,\n    Insert,\n    Delete,\n\n    // Numpad keys which have not been implemented: NumpadSeparator NumLock\n    Numpad0,\n    Numpad1,\n    Numpad2,\n    Numpad3,\n    Numpad4,\n    Numpad5,\n    Numpad6,\n    Numpad7,\n    Numpad8,\n    Numpad9,\n    NumpadSubtract,\n    NumpadAdd,\n    NumpadDivide,\n    NumpadMultiply,\n    NumpadEquals,\n    NumpadEnter,\n    NumpadDecimal,\n\n    // The following keys names represent the position of the key in a US keyboard,\n    // not the sign value. In a different keyboards and OS, the position can vary.\n    Grave,\n    Minus,\n    Equal,\n    LeftBracket,\n    RightBracket,\n    BackSlash,\n    Semicolon,\n    Apostrophe,\n    Comma,\n    Dot,\n    Slash,\n}\n\nimpl FromStr for Keycode {\n    type Err = String;\n    fn from_str(s: &str) -> Result<Self, Self::Err> {\n        match s {\n            \"Key0\" => Ok(Self::Key0),\n            \"Key1\" => Ok(Self::Key1),\n            \"Key2\" => Ok(Self::Key2),\n            \"Key3\" => Ok(Self::Key3),\n            \"Key4\" => Ok(Self::Key4),\n            \"Key5\" => Ok(Self::Key5),\n            \"Key6\" => Ok(Self::Key6),\n            \"Key7\" => Ok(Self::Key7),\n            \"Key8\" => Ok(Self::Key8),\n            \"Key9\" => Ok(Self::Key9),\n            \"A\" => Ok(Self::A),\n            \"B\" => Ok(Self::B),\n            \"C\" => Ok(Self::C),\n            \"D\" => Ok(Self::D),\n            \"E\" => Ok(Self::E),\n            \"F\" => Ok(Self::F),\n            \"G\" => Ok(Self::G),\n            \"H\" => Ok(Self::H),\n            \"I\" => Ok(Self::I),\n            \"J\" => Ok(Self::J),\n            \"K\" => Ok(Self::K),\n            \"L\" => Ok(Self::L),\n            \"M\" => Ok(Self::M),\n            \"N\" => Ok(Self::N),\n            \"O\" => Ok(Self::O),\n            \"P\" => Ok(Self::P),\n            \"Q\" => Ok(Self::Q),\n            \"R\" => Ok(Self::R),\n            \"S\" => Ok(Self::S),\n            \"T\" => Ok(Self::T),\n            \"U\" => Ok(Self::U),\n            \"V\" => Ok(Self::V),\n            \"W\" => Ok(Self::W),\n            \"X\" => Ok(Self::X),\n            \"Y\" => Ok(Self::Y),\n            \"Z\" => Ok(Self::Z),\n            \"F1\" => Ok(Self::F1),\n            \"F2\" => Ok(Self::F2),\n            \"F3\" => Ok(Self::F3),\n            \"F4\" => Ok(Self::F4),\n            \"F5\" => Ok(Self::F5),\n            \"F6\" => Ok(Self::F6),\n            \"F7\" => Ok(Self::F7),\n            \"F8\" => Ok(Self::F8),\n            \"F9\" => Ok(Self::F9),\n            \"F10\" => Ok(Self::F10),\n            \"F11\" => Ok(Self::F11),\n            \"F12\" => Ok(Self::F12),\n            \"F13\" => Ok(Self::F13),\n            \"F14\" => Ok(Self::F14),\n            \"F15\" => Ok(Self::F15),\n            \"F16\" => Ok(Self::F16),\n            \"F17\" => Ok(Self::F17),\n            \"F18\" => Ok(Self::F18),\n            \"F19\" => Ok(Self::F19),\n            \"F20\" => Ok(Self::F20),\n            \"Escape\" => Ok(Self::Escape),\n            \"Space\" => Ok(Self::Space),\n            \"LControl\" => Ok(Self::LControl),\n            \"RControl\" => Ok(Self::RControl),\n            \"LShift\" => Ok(Self::LShift),\n            \"RShift\" => Ok(Self::RShift),\n            \"LAlt\" => Ok(Self::LAlt),\n            \"RAlt\" => Ok(Self::RAlt),\n            // TODO rename `Command` into `RCommand` at new major release\n            \"Command\" => Ok(Self::Command),\n            \"RCommand\" => Ok(Self::RCommand),\n            \"LOption\" => Ok(Self::LOption),\n            \"ROption\" => Ok(Self::ROption),\n            \"LMeta\" => Ok(Self::LMeta),\n            \"RMeta\" => Ok(Self::RMeta),\n            \"Enter\" => Ok(Self::Enter),\n            \"Up\" => Ok(Self::Up),\n            \"Down\" => Ok(Self::Down),\n            \"Left\" => Ok(Self::Left),\n            \"Right\" => Ok(Self::Right),\n            \"Backspace\" => Ok(Self::Backspace),\n            \"CapsLock\" => Ok(Self::CapsLock),\n            \"Tab\" => Ok(Self::Tab),\n            \"Home\" => Ok(Self::Home),\n            \"End\" => Ok(Self::End),\n            \"PageUp\" => Ok(Self::PageUp),\n            \"PageDown\" => Ok(Self::PageDown),\n            \"Insert\" => Ok(Self::Insert),\n            \"Delete\" => Ok(Self::Delete),\n            \"Numpad0\" => Ok(Self::Numpad0),\n            \"Numpad1\" => Ok(Self::Numpad1),\n            \"Numpad2\" => Ok(Self::Numpad2),\n            \"Numpad3\" => Ok(Self::Numpad3),\n            \"Numpad4\" => Ok(Self::Numpad4),\n            \"Numpad5\" => Ok(Self::Numpad5),\n            \"Numpad6\" => Ok(Self::Numpad6),\n            \"Numpad7\" => Ok(Self::Numpad7),\n            \"Numpad8\" => Ok(Self::Numpad8),\n            \"Numpad9\" => Ok(Self::Numpad9),\n            \"NumpadSubtract\" => Ok(Self::NumpadSubtract),\n            \"NumpadAdd\" => Ok(Self::NumpadAdd),\n            \"NumpadDivide\" => Ok(Self::NumpadDivide),\n            \"NumpadMultiply\" => Ok(Self::NumpadMultiply),\n            \"NumpadEquals\" => Ok(Self::NumpadEquals),\n            \"NumpadEnter\" => Ok(Self::NumpadEnter),\n            \"NumpadDecimal\" => Ok(Self::NumpadDecimal),\n            \"Grave\" => Ok(Self::Grave),\n            \"Minus\" => Ok(Self::Minus),\n            \"Equal\" => Ok(Self::Equal),\n            \"LeftBracket\" => Ok(Self::LeftBracket),\n            \"RightBracket\" => Ok(Self::RightBracket),\n            \"BackSlash\" => Ok(Self::BackSlash),\n            \"Semicolon\" => Ok(Self::Semicolon),\n            \"Apostrophe\" => Ok(Self::Apostrophe),\n            \"Comma\" => Ok(Self::Comma),\n            \"Dot\" => Ok(Self::Dot),\n            \"Slash\" => Ok(Self::Slash),\n            _ => Err(String::from(\"failed to parse keycode\")),\n        }\n    }\n}\n\nimpl fmt::Display for Keycode {\n    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n        write!(f, \"{:?}\", self)\n    }\n}\n"
  },
  {
    "path": "src/lib.rs",
    "content": "//! A simple library for querying mouse and keyboard state without requiring\n//! an active window. Currently works in Windows, Linux, and macOS.\n//!\n//! ```no_run\n//! use device_query::{DeviceQuery, DeviceState, MouseState, Keycode};\n//!\n//! let device_state = DeviceState::new();\n//!\n//! let mouse: MouseState = device_state.get_mouse();\n//! println!(\"Current Mouse Coordinates: {:?}\", mouse.coords);\n//!\n//! let keys: Vec<Keycode> = device_state.get_keys();\n//! println!(\"Is A pressed? {}\", keys.contains(&Keycode::A));\n//! ```\n//!\n//! It's also possible to listen for events.\n//! ```no_run\n//!  use device_query::{DeviceEvents, DeviceEventsHandler};\n//!  use std::time::Duration;\n//!\n//!  let device_state = DeviceEventsHandler::new(Duration::from_millis(10))\n//!     .expect(\"Failed to start event loop\");\n//!\n//!  // Register a key down event callback\n//!  // The guard is used to keep the callback alive\n//!  let _guard = device_state.on_mouse_move(|position| {\n//!     println!(\"Mouse position: {:#?}\", position);\n//!  });\n//!\n//!  // Keep the main thread alive\n//!  loop {}\n//! ```\n\n#[cfg(target_os = \"windows\")]\nextern crate windows;\n\npub mod device_events;\npub mod device_query;\npub mod device_state;\npub mod keymap;\npub mod mouse_state;\n\npub use device_events::*;\npub use device_query::*;\npub use device_state::*;\npub use keymap::*;\npub use mouse_state::*;\n"
  },
  {
    "path": "src/mouse_state.rs",
    "content": "//! Description of mouse coordinates and state of buttons.\n\n/// Mouse position.\npub type MousePosition = (i32, i32);\n\n/// MouseButton.\npub type MouseButton = usize;\n\n#[derive(Debug, PartialEq, Default, Clone)]\n/// A simple structure containing the current mouse coordinates and the\n/// state of each mouse button that we can query. Currently, Windows and\n/// Linux provide nice ways to query five mouse buttons. Since button\n/// numbers are 1-based, `button_pressed[0]` is assumed to be false and\n/// have no meaning.\npub struct MouseState {\n    /// Coordinates in pixel.\n    pub coords: MousePosition,\n    /// State of each mouse button.\n    pub button_pressed: Vec<bool>,\n}\n"
  }
]