一个简单的库,用于在无窗口的情况下查询鼠标和键盘输入。可在 Windows、Linux 和 macOS 中使用。
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 = device_state.get_keys();
println!("Is A pressed? {}", keys.contains(Keycode::A));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-devOn Fedora/RHEL/CentOS:
sudo dnf install xorg-x11-server-develOn 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:
device_query (such as your terminal) to the listdevice_query allows you to register callbacks for various device events such as key presses and mouse movements.
Here's a simple example demonstrating how to use the callback system:
…暂无开放 Issues,或尚未同步最近议题。