2

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?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Okano
  • 232
  • 2
  • 9

1 Answers1

2

Your error message states (reformatted to make it more readable):

Command {
    command: "pkg-config" "--libs" "--cflags" "x11" "x11 >= 1.4.99.1",
    cause: Os {
        code: 2,
        kind: NotFound, 
        message: "No such file or directory",
    }
}

This means that it tried to run the command "pkg-config" "--libs" "--cflags" "x11" "x11 >= 1.4.99.1" but it failed. It failed because the binary pkg-config could not be found.

If you were to run this command in the terminal, presumably you'd see the same error. If so, you need to install pkg-config. If not, then pkg-config might not be in your PATH or is otherwise unavailable to your Rust program. You'll need to investigate where it's installed and why that installation path isn't available to the program.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366