#keyboard-input #mouse-input #input #mouse #keyboard

device_query

A basic library for querying keyboard and mouse state on-demand without a window

19 releases (6 stable)

Uses old Rust 2015

2.0.0 Feb 9, 2024
1.1.3 Mar 31, 2023
1.1.2 Jan 14, 2023
1.1.1 May 18, 2022
0.1.0 Apr 3, 2018

#50 in Hardware support

Download history 488/week @ 2024-01-20 339/week @ 2024-01-27 410/week @ 2024-02-03 574/week @ 2024-02-10 748/week @ 2024-02-17 717/week @ 2024-02-24 685/week @ 2024-03-02 946/week @ 2024-03-09 882/week @ 2024-03-16 916/week @ 2024-03-23 1220/week @ 2024-03-30 896/week @ 2024-04-06 964/week @ 2024-04-13 889/week @ 2024-04-20 915/week @ 2024-04-27 746/week @ 2024-05-04

3,595 downloads per month
Used in 31 crates (28 directly)

MIT license

55KB
1.5K SLoC

device_query

Build Status

A simple library to query mouse and keyboard inputs on demand without a window. Will work in Windows, Linux on X11, and macOS.

use device_query::{DeviceQuery, DeviceState, MouseState, Keycode};

let device_state = DeviceState::new();
let mouse: MouseState = device_state.get_mouse();
println!("Current Mouse Coordinates: {:?}", mouse.coords);
let keys: Vec<Keycode> = device_state.get_keys();
println!("Is A pressed? {}", keys.contains(Keycode::A));

Dependencies

Windows shouldn't require any special software to be installed for device_query to work properly. On Linux, the X11 development libraries are required for device_query to query state from the OS.

On Ubuntu/Debian:

sudo apt install libx11-dev

On Fedora/RHEL/CentOS:

sudo dnf install xorg-x11-server-devel

On newer versions of MacOS, you may run into issues where you only see meta keys such as shift, backspace, et cetera. This is due to a permission issue. To work around this:

  • open the MacOS system preferences
  • go to Security -> Privacy
  • scroll down to Accessibility and unlock it
  • add the app that is using device_query (such as your terminal) to the list

Dependencies

~0–40MB
~558K SLoC