Fix: make usable on Windows and Linux

This commit is contained in:
Dorian Zedler 2023-02-11 14:52:58 +01:00
parent c7a16abb1e
commit ee53708636
Signed by: dorian
GPG key ID: 989DE36109AFA354
3 changed files with 29 additions and 3 deletions

View file

@ -14,5 +14,9 @@ crypto_helper = {path = "../crypto_helper"}
uuid = { version = "1.3.0", features = ["serde", "v4"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
[target.'cfg(unix)'.dependencies]
enigo = "0.0.14"
[target.'cfg(windows)'.dependencies]
simulate = "0.3.0"

20
receiver/src/keyboard.rs Normal file
View file

@ -0,0 +1,20 @@
#[cfg(target_family = "unix")]
use enigo::{KeyboardControllable};
pub fn type_text(text: &str) {
enigo::Enigo::default().key_sequence(text);
}
pub fn click_tab() {
enigo::Enigo::default().key_click(enigo::Key::Tab);
}
#[cfg(target_family = "windows")]
pub fn type_text(&self, text: &str) {
simulate::type_str(text);
}
#[cfg(target_family = "windows")]
pub fn click_tab(&self) {
simulate::send(simulate::Key::Tab);
}

View file

@ -3,6 +3,8 @@ use std::time::Duration;
extern crate paho_mqtt as mqtt;
mod keyboard;
#[derive(Serialize, Deserialize, PartialEq)]
enum MqttMessageKind {
Time,
@ -75,9 +77,9 @@ fn main() {
let time_with_comma = millis_to_string(msg.time);
println!("Trying to type {time_with_comma}");
simulate::type_str(&time_with_comma);
simulate::send(simulate::Key::Tab);
simulate::send(simulate::Key::Tab);
keyboard::type_text(&time_with_comma);
keyboard::click_tab();
keyboard::click_tab();
let reply = MqttMessage {
id: msg.id,