Additional logging, translate other keys
This commit is contained in:
parent
89e9d13d64
commit
68b8d4db3d
81
Cargo.lock
generated
81
Cargo.lock
generated
|
@ -30,12 +30,6 @@ dependencies = [
|
|||
"iovec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
|
@ -72,6 +66,12 @@ version = "0.12.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.3"
|
||||
|
@ -84,13 +84,14 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "input"
|
||||
version = "0.6.0"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f68c2be575d5695a03d446acd1016b1665b26172fb37a75300459abeffba09d1"
|
||||
checksum = "f95640ef27dac9b23ef1fbd760c67a88ce3cab2143a2c18390e71f39c53b815f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"input-sys",
|
||||
"libc",
|
||||
"log",
|
||||
"udev",
|
||||
]
|
||||
|
||||
|
@ -105,14 +106,15 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "inputbot"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8bc90284daff09ee1df087ae5f74ac724749dc26ed6e9fce7fd69e11e2a44284"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/obv-mikhail/InputBot?branch=develop#f5e94cad04779f0d43ebcf07ef313ead5c1ef233"
|
||||
dependencies = [
|
||||
"input",
|
||||
"libc",
|
||||
"nix 0.22.3",
|
||||
"nix 0.24.3",
|
||||
"once_cell",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"uinput",
|
||||
"winapi",
|
||||
"x11",
|
||||
|
@ -149,6 +151,15 @@ dependencies = [
|
|||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
|
@ -186,12 +197,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.22.3"
|
||||
version = "0.24.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf"
|
||||
checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cc",
|
||||
"cfg-if 1.0.0",
|
||||
"libc",
|
||||
"memoffset",
|
||||
|
@ -257,6 +267,12 @@ dependencies = [
|
|||
"nom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.160"
|
||||
|
@ -274,7 +290,7 @@ checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.15",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -286,6 +302,39 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.24.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"
|
||||
dependencies = [
|
||||
"strum_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.24.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.15"
|
||||
|
|
|
@ -6,7 +6,7 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
inputbot = "0.5.1"
|
||||
inputbot = { git = "https://github.com/obv-mikhail/InputBot", branch = "develop" }
|
||||
rosc = "0.10.0"
|
||||
serde = { version = "1.0.160", features = ["derive"] }
|
||||
toml = "0.7.3"
|
||||
|
|
38
src/main.rs
38
src/main.rs
|
@ -1,24 +1,26 @@
|
|||
extern crate inputbot;
|
||||
|
||||
use std::{net::{SocketAddrV4, UdpSocket}, str::FromStr};
|
||||
|
||||
use rosc::OscPacket;
|
||||
use toml;
|
||||
use serde::Deserialize;
|
||||
use inputbot::{KeybdKey, KeybdKey::*};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use inputbot::{KeybdKey, KeybdKey::*, get_keybd_key};
|
||||
|
||||
// Configuration struct with mapping of OSC addresses to keyboard keys, and a general server configuration.
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct Config {
|
||||
server: ServerConfig,
|
||||
// Mappings is called mapping in config
|
||||
#[serde(rename = "mapping")]
|
||||
mappings: Vec<EventKeyMapping>,
|
||||
}
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct EventKeyMapping {
|
||||
event: String,
|
||||
key: String,
|
||||
}
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct ServerConfig {
|
||||
port: u16,
|
||||
}
|
||||
|
@ -34,12 +36,17 @@ fn main() {
|
|||
|
||||
let mut event_key_map = std::collections::HashMap::new();
|
||||
for mapping in config.mappings {
|
||||
// Convert the key string to a KeybdKey
|
||||
// Convert the key string to a KeybdKey. First try to convert it to an F key, then to a normal key by matching the char.
|
||||
let key = match to_fkey(&mapping.key) {
|
||||
Some(k) => k,
|
||||
None => {
|
||||
match mapping.key.chars().next() {
|
||||
Some(c) => get_keybd_key(c).unwrap(),
|
||||
None => {
|
||||
println!("Invalid key: {}", mapping.key);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
event_key_map.insert(mapping.event, key);
|
||||
|
@ -71,6 +78,18 @@ fn main() {
|
|||
}
|
||||
|
||||
fn load_config() -> Result<Config, String> {
|
||||
// If the config file isn't found, create one with default values
|
||||
if !std::path::Path::new("config.toml").exists() {
|
||||
let default_config = Config {
|
||||
server: ServerConfig {
|
||||
port: 9000,
|
||||
},
|
||||
mappings: vec![],
|
||||
};
|
||||
let toml = toml::to_string_pretty(&default_config).map_err(|e| e.to_string())?;
|
||||
std::fs::write("config.toml", toml).map_err(|e| e.to_string())?;
|
||||
println!("Created default config file at config.toml");
|
||||
}
|
||||
let config_file = std::fs::read_to_string("config.toml").map_err(|e| e.to_string())?;
|
||||
let config: Config = toml::from_str(&config_file).map_err(|e| e.to_string())?;
|
||||
Ok(config)
|
||||
|
@ -79,6 +98,10 @@ fn load_config() -> Result<Config, String> {
|
|||
fn handle_packet(packet: OscPacket, mappings: &std::collections::HashMap<String, KeybdKey>) {
|
||||
match packet {
|
||||
OscPacket::Message(msg) => {
|
||||
// Print message
|
||||
println!("OSC Message: {:?}", msg);
|
||||
// Print address
|
||||
println!("OSC Address: {}", msg.addr);
|
||||
// Match event to key
|
||||
let key = match mappings.get(&msg.addr) {
|
||||
Some(k) => k,
|
||||
|
@ -87,6 +110,7 @@ fn handle_packet(packet: OscPacket, mappings: &std::collections::HashMap<String,
|
|||
}
|
||||
};
|
||||
// Press key
|
||||
println!("Pressing key: {:?}", key);
|
||||
key.press();
|
||||
}
|
||||
OscPacket::Bundle(bundle) => {
|
||||
|
|
Loading…
Reference in a new issue