I’m trying to track which keys are typed in WSL using the device_query crate. I’ve read the crate’s documentation, added device_query = "0.2.4"
to my Cargo.toml file and installed the X11 dependency (sudo apt install libx11-dev
).
In my src/main.rs file, I use the crate as intended:
use device_query::{DeviceQuery, DeviceState, MouseState, Keycode};
fn main() {
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));
}
However, when I run cargo build
, I get a 101 exit error:
Updating crates.io index
Compiling x11 v2.18.2
error: failed to run custom build command for `x11 v2.18.2`
Caused by:
process didn't exit successfully: `/home/egerou/Coding/Rust/Wow/target/debug/build/x11-5b031a8b4760d83b/build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Command { command: "\"pkg-config\" \"--libs\" \"--cflags\" \"x11\" \"x11 >= 1.4.99.1\"", cause: Os { code: 2, kind: NotFound, message: "No such file or directory" } }', /home/egerou/.cargo/registry/src/github.com-1ecc6299db9ec823/x11-2.18.2/build.rs:36:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
When I read the error, I feel like X11 might not be installed correctly, but if I compile without the device_query = "0.2.4"
crate but still the X11 crate (x11 = "2.18.2"
), cargo build
works.
The error also says a file is missing. Maybe since I’m on WSL, the file isn’t at the correct/expected location.
I’m also using the indexmap = "1.3.2"
and rand = "0.5.5" crates
. I don’t think they would interfere with the device_query = "0.2.4"
crate.
How to build a project that uses the device_query = "0.2.4"
crate?