diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index f9a0b96..a60f0d7 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,4 +1,5 @@ use enigo::{Direction::Click, Enigo, Key, Keyboard, Settings}; +#[cfg(target_os = "linux")] use std::ptr; use tauri::Manager; @@ -10,10 +11,34 @@ fn greet(name: &str) -> String { format!("Hello, {}! You've been greeted from Rust!", name) } +#[tauri::command] +fn send_key(key: String) -> Result<(), String> { + let mut enigo = Enigo::new(&Settings::default()).map_err(|e| format!("Enigo error: {}", e))?; + + if key.len() == 1 { + // Single letter (a-z, A-Z) + enigo.key(Key::Unicode(key.chars().next().unwrap()), Click) + .map_err(|e| format!("Key error: {}", e))?; + } else { + // Special keys + match key.as_str() { + "Enter" => enigo.key(Key::Return, Click) + .map_err(|e| format!("Key error: {}", e))?, + "Space" => enigo.key(Key::Space, Click) + .map_err(|e| format!("Key error: {}", e))?, + "Backspace" => enigo.key(Key::Backspace, Click) + .map_err(|e| format!("Key error: {}", e))?, + _ => return Err("Unknown key".to_string()), + } + } + Ok(()) +} + #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() .setup(|app| { + #[cfg_attr(not(target_os = "linux"), allow(unused_variables))] let window = app.get_webview_window("main").unwrap(); #[cfg(target_os = "linux")] { @@ -40,7 +65,7 @@ pub fn run() { Ok(()) }) .plugin(tauri_plugin_opener::init()) - .invoke_handler(tauri::generate_handler![greet]) + .invoke_handler(tauri::generate_handler![greet, send_key]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/src/app/app.component.css b/src/app/app.component.css index c68d181..20354c4 100644 --- a/src/app/app.component.css +++ b/src/app/app.component.css @@ -110,3 +110,50 @@ button { background-color: #0f0f0f69; } } + +.keyboard { + display: flex; + flex-direction: column; + gap: 8px; + padding: 20px; + background: #f5f5f5; + border-radius: 10px; +} + +.keyboard-row { + display: flex; + gap: 6px; + justify-content: center; +} + +.key-button { + min-width: 60px; + height: 60px; + font-size: 20px; + font-weight: bold; + border: 2px solid #ddd; + border-radius: 8px; + background: rgb(58, 56, 56); + cursor: pointer; + transition: all 0.1s; +} + +.key-button:hover { + background: #979797; + border-color: #999; +} + +.key-button:active { + background: #d0d0d0; + transform: scale(0.95); +} + +.shift-key.active { + background: #4CAF50; + color: white; + border-color: #45a049; +} + +.space-key { + min-width: 300px; +} diff --git a/src/app/app.component.html b/src/app/app.component.html index e447606..b5d1d17 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -16,4 +16,56 @@
{{ greetingMessage }}
+