This commit is contained in:
Crispy 2023-05-21 18:14:44 +02:00
commit 281d643a71
6 changed files with 270 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
/target
*.txt
!example.txt

1
.rustfmt.toml Normal file
View file

@ -0,0 +1 @@
hard_tabs=true

181
Cargo.lock generated Normal file
View file

@ -0,0 +1,181 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "core-foundation"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "core-graphics"
version = "0.22.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb"
dependencies = [
"bitflags",
"core-foundation",
"core-graphics-types",
"foreign-types",
"libc",
]
[[package]]
name = "core-graphics-types"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b"
dependencies = [
"bitflags",
"core-foundation",
"foreign-types",
"libc",
]
[[package]]
name = "enigo"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "464c869256b1d6c1db151ab7a164fe0a5a6d340095460f92d7e8fba78ab47dc0"
dependencies = [
"core-graphics",
"libc",
"objc",
"pkg-config",
"windows",
]
[[package]]
name = "foreign-types"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
dependencies = [
"foreign-types-shared",
]
[[package]]
name = "foreign-types-shared"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "libc"
version = "0.2.144"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1"
[[package]]
name = "malloc_buf"
version = "0.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
dependencies = [
"libc",
]
[[package]]
name = "objc"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
dependencies = [
"malloc_buf",
]
[[package]]
name = "pkg-config"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
[[package]]
name = "programmer"
version = "0.1.0"
dependencies = [
"enigo",
]
[[package]]
name = "windows"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
[[package]]
name = "windows_i686_gnu"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
[[package]]
name = "windows_i686_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"

9
Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "programmer"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
enigo = "0.1.2"

16
example.txt Normal file
View file

@ -0,0 +1,16 @@
0000 0000 0000 0000
0001 0000 0000 0000
0010 0000 0000 0000
0011 0000 0000 0000
0100 0000 0000 0000
0101 0000 0000 0000
0110 0000 0000 0000
0111 0000 0000 0000
1000 0000 0000 0000
1001 0000 00000000
1010 0000 0000
1011 0000 0000 0000
1100 0000
1101 1111 0000
1110 1111 00000000
1111

60
src/main.rs Normal file
View file

@ -0,0 +1,60 @@
use enigo::*;
use std::{env, fs, process::exit, thread, time::Duration};
const WRITE_KEY: Key = Key::Layout('j');
const BIT_KEYS: [Key; 16] = [
Key::Layout('0'),
Key::Layout('1'),
Key::Layout('2'),
Key::Layout('3'),
Key::Layout('4'),
Key::Layout('5'),
Key::Layout('6'),
Key::Layout('7'),
Key::Layout('8'),
Key::Layout('9'),
Key::Layout('a'),
Key::Layout('b'),
Key::Layout('c'),
Key::Layout('d'),
Key::Layout('e'),
Key::Layout('f'),
];
fn main() {
let path = env::args().skip(1).next().unwrap_or_else(|| {
println!("no path specified");
exit(0)
});
let file = fs::read_to_string(path).unwrap();
thread::sleep(Duration::from_millis(2000));
let mut eni = Enigo::new();
for line in file.lines() {
let mut keys = Vec::new();
let mut index = 16;
for c in line.chars() {
if c == '0' {
index -= 1;
} else if c == '1' {
index -= 1;
keys.push(BIT_KEYS[index]);
}
if index == 0 {
break;
}
}
for k in keys.clone() {
eni.key_down(k);
}
eni.key_down(WRITE_KEY);
thread::sleep(Duration::from_millis(50));
eni.key_up(WRITE_KEY);
thread::sleep(Duration::from_millis(50));
for k in keys {
eni.key_up(k);
}
thread::sleep(Duration::from_millis(50));
}
}