Fix: make usable on Windows and Linux
This commit is contained in:
parent
c7a16abb1e
commit
ee53708636
3 changed files with 29 additions and 3 deletions
|
@ -14,5 +14,9 @@ crypto_helper = {path = "../crypto_helper"}
|
||||||
uuid = { version = "1.3.0", features = ["serde", "v4"] }
|
uuid = { version = "1.3.0", features = ["serde", "v4"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
||||||
|
[target.'cfg(unix)'.dependencies]
|
||||||
enigo = "0.0.14"
|
enigo = "0.0.14"
|
||||||
|
|
||||||
|
[target.'cfg(windows)'.dependencies]
|
||||||
simulate = "0.3.0"
|
simulate = "0.3.0"
|
||||||
|
|
20
receiver/src/keyboard.rs
Normal file
20
receiver/src/keyboard.rs
Normal 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);
|
||||||
|
}
|
|
@ -3,6 +3,8 @@ use std::time::Duration;
|
||||||
|
|
||||||
extern crate paho_mqtt as mqtt;
|
extern crate paho_mqtt as mqtt;
|
||||||
|
|
||||||
|
mod keyboard;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, PartialEq)]
|
#[derive(Serialize, Deserialize, PartialEq)]
|
||||||
enum MqttMessageKind {
|
enum MqttMessageKind {
|
||||||
Time,
|
Time,
|
||||||
|
@ -75,9 +77,9 @@ fn main() {
|
||||||
let time_with_comma = millis_to_string(msg.time);
|
let time_with_comma = millis_to_string(msg.time);
|
||||||
|
|
||||||
println!("Trying to type {time_with_comma}");
|
println!("Trying to type {time_with_comma}");
|
||||||
simulate::type_str(&time_with_comma);
|
keyboard::type_text(&time_with_comma);
|
||||||
simulate::send(simulate::Key::Tab);
|
keyboard::click_tab();
|
||||||
simulate::send(simulate::Key::Tab);
|
keyboard::click_tab();
|
||||||
|
|
||||||
let reply = MqttMessage {
|
let reply = MqttMessage {
|
||||||
id: msg.id,
|
id: msg.id,
|
||||||
|
|
Loading…
Reference in a new issue