try keyborad detector

This commit is contained in:
yanweitong 2023-08-14 18:27:08 +08:00
parent 45dc7652df
commit ea08b62096
8 changed files with 170 additions and 9 deletions

123
Cargo.lock generated
View File

@ -32,6 +32,12 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
[[package]]
name = "bumpalo"
version = "3.13.0"
@ -90,7 +96,7 @@ version = "0.22.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb"
dependencies = [
"bitflags",
"bitflags 1.3.2",
"core-foundation",
"core-graphics-types",
"foreign-types",
@ -103,7 +109,7 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bb142d41022986c1d8ff29103a1411c8a3dfad3552f87a4f8dc50d61d4f4e33"
dependencies = [
"bitflags",
"bitflags 1.3.2",
"core-foundation",
"libc",
]
@ -160,6 +166,31 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crossterm"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df"
dependencies = [
"bitflags 2.4.0",
"crossterm_winapi",
"libc",
"mio",
"parking_lot",
"signal-hook",
"signal-hook-mio",
"winapi",
]
[[package]]
name = "crossterm_winapi"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b"
dependencies = [
"winapi",
]
[[package]]
name = "crunchy"
version = "0.2.2"
@ -441,6 +472,18 @@ dependencies = [
"simd-adler32",
]
[[package]]
name = "mio"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
dependencies = [
"libc",
"log",
"wasi",
"windows-sys",
]
[[package]]
name = "nanorand"
version = "0.7.0"
@ -454,6 +497,7 @@ dependencies = [
name = "nezha"
version = "0.1.0"
dependencies = [
"crossterm",
"enigo",
"image",
"screenshots",
@ -514,6 +558,29 @@ version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-targets",
]
[[package]]
name = "percent-encoding"
version = "2.3.0"
@ -552,7 +619,7 @@ version = "0.17.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59871cc5b6cce7eaccca5a802b4173377a1c2ba90654246789a8fa2334426d11"
dependencies = [
"bitflags",
"bitflags 1.3.2",
"crc32fast",
"fdeflate",
"flate2",
@ -617,6 +684,15 @@ dependencies = [
"num_cpus",
]
[[package]]
name = "redox_syscall"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
@ -641,6 +717,36 @@ dependencies = [
"xcb",
]
[[package]]
name = "signal-hook"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801"
dependencies = [
"libc",
"signal-hook-registry",
]
[[package]]
name = "signal-hook-mio"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af"
dependencies = [
"libc",
"mio",
"signal-hook",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
dependencies = [
"libc",
]
[[package]]
name = "simd-adler32"
version = "0.3.7"
@ -793,6 +899,15 @@ dependencies = [
"windows-targets",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.48.1"
@ -856,7 +971,7 @@ version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb3acf6b0945550d37d3a683b8f7de9d9f66b2c14dc390313b34d7ac6f1b4089"
dependencies = [
"bitflags",
"bitflags 1.3.2",
"libc",
"quick-xml",
]

View File

@ -10,11 +10,12 @@ edition = "2021"
default = ["pokemmo"]
pokemmo = ["screen","ocr","joystick","dep:image"]
pokemmo = ["screen","ocr","joystick","dep:image","pokemon","detector"]
screen = ["dep:screenshots"]
ocr = []
joystick = ["dep:enigo"]
pokemon = []
detector = ["dep:crossterm"]
[lib]
@ -22,7 +23,8 @@ name = "nezha"
path = "src/lib.rs"
[dependencies]
log = "0.4.20"
enigo = { version = "0.1.2", optional = true }
screenshots = { version = "0.7.0", optional = true }
image = {version = "0.24.6", optional = true}
image = {version = "0.24.6", optional = true}
crossterm = {version = "0.27.0", optional = true}

4
src/detector/detector.rs Normal file
View File

@ -0,0 +1,4 @@
#[cfg(feature = "detector")]
pub(crate) mod detector{
}

View File

@ -0,0 +1,31 @@
#[cfg(test)]
mod tests {
use std::thread;
use std::time::Duration;
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers, read};
#[test]
fn detect_keyboard() {
println!("no thing happened.");
println!("start loop ... ");
loop {
//matching the key
match read().unwrap() {
//i think this speaks for itself
Event::Key(KeyEvent {
code: KeyCode::Char('a'),
modifiers: KeyModifiers::NONE, ..
//clearing the screen and printing our message
}) => {
println!("detect press A!")
}
_ => {
println!("no thing happened.")
}
}
thread::sleep(Duration::from_secs(1));
}
// thread::sleep(Duration::from_secs(20));
}
}

2
src/detector/mod.rs Normal file
View File

@ -0,0 +1,2 @@
pub(crate) mod detector;
mod detector_test;

View File

@ -1,3 +1,5 @@
pub(crate) mod screen;
pub(crate) mod joystick;
pub(crate) mod pokemmo;
pub(crate) mod pokemmo;
pub(crate) mod pokemon;
pub(crate) mod detector;

1
src/pokemon/mod.rs Normal file
View File

@ -0,0 +1 @@
mod pokemon;

4
src/pokemon/pokemon.rs Normal file
View File

@ -0,0 +1,4 @@
#[cfg(feature = "pokemon")]
pub(crate) mod pokemon{
}