我正在尝试使用device_query crate 跟踪在 WSL 中键入了哪些键。我已经阅读了 crate 的文档,添加device_query = "0.2.4"
到我的 Cargo.toml 文件并安装了 X11 依赖项 ( sudo apt install libx11-dev
)。
在我的 src/main.rs 文件中,我按预期使用了 crate:
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));
}
但是,当我运行时cargo build
,出现 101 退出错误:
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
当我读到错误时,我觉得 X11 可能没有正确安装,但是如果我在没有device_query = "0.2.4"
crate 的情况下编译但仍然是 X11 crate ( x11 = "2.18.2"
),则cargo build
可以。
该错误还表示文件丢失。也许因为我在 WSL 上,所以文件不在正确/预期的位置。
我也在使用indexmap = "1.3.2"
and rand = "0.5.5" crates
。我不认为他们会干扰device_query = "0.2.4"
板条箱。
如何构建一个使用device_query = "0.2.4"
crate 的项目?