81 lines
2.1 KiB
Rust
81 lines
2.1 KiB
Rust
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
|
|
|
use enigo::{Enigo, Key, KeyboardControllable, MouseControllable};
|
|
use std::thread;
|
|
use std::time::Duration;
|
|
use arboard::Clipboard;
|
|
|
|
#[tauri::command]
|
|
fn get_mouse_pos() -> String {
|
|
let enigo = Enigo::new();
|
|
let (x, y) = enigo.mouse_location();
|
|
format!("{{ \"x\": {}, \"y\": {} }}", x, y).into()
|
|
}
|
|
|
|
#[tauri::command]
|
|
fn type_str(input: String) {
|
|
#[cfg(dev)]
|
|
println!(">: {}", input);
|
|
|
|
let mut enigo = Enigo::new();
|
|
let mut clipboard = Clipboard::new().unwrap();
|
|
|
|
// Load input into clipboard
|
|
clipboard.set_text(input).unwrap();
|
|
|
|
// TODO: Set the Command/Alt key configured by user
|
|
#[cfg(target_os = "macos")] {
|
|
enigo.key_down(Key::Command);
|
|
enigo.key_click(Key::Tab);
|
|
enigo.key_up(Key::Command);
|
|
}
|
|
|
|
#[cfg(target_os = "windows")] {
|
|
enigo.key_down(Key::Alt);
|
|
enigo.key_click(Key::Tab);
|
|
enigo.key_up(Key::Alt);
|
|
}
|
|
|
|
#[cfg(target_os = "linux")] {
|
|
enigo.key_down(Key::Alt);
|
|
enigo.key_click(Key::Tab);
|
|
enigo.key_up(Key::Alt);
|
|
}
|
|
|
|
thread::sleep(Duration::from_millis(200));
|
|
|
|
#[cfg(target_os = "windows")]{
|
|
enigo.key_down(Key::Control);
|
|
enigo.key_click(Key::Layout('v'));
|
|
enigo.key_up(Key::Control);
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]{
|
|
enigo.key_down(Key::Command);
|
|
enigo.key_click(Key::Layout('v'));
|
|
enigo.key_up(Key::Command);
|
|
}
|
|
|
|
#[cfg(target_os = "linux")]{
|
|
enigo.key_down(Key::Control);
|
|
enigo.key_click(Key::Layout('v'));
|
|
enigo.key_up(Key::Control);
|
|
}
|
|
|
|
thread::sleep(Duration::from_millis(20));
|
|
|
|
// Close program
|
|
#[cfg(not(dev))]
|
|
std::process::exit(0);
|
|
|
|
}
|
|
|
|
fn main() {
|
|
tauri::Builder::default()
|
|
.plugin(tauri_plugin_positioner::init())
|
|
.invoke_handler(tauri::generate_handler![type_str, get_mouse_pos])
|
|
.run(tauri::generate_context!())
|
|
.expect("error while running tauri application");
|
|
}
|