From d252f8e1aee584c2f41f22989c12051f714c3c1c Mon Sep 17 00:00:00 2001 From: Vlad Gerasimov Date: Mon, 28 Jul 2025 18:32:18 +0400 Subject: [PATCH 1/2] fix(utils): use virtual key codes for cross-layout paste --- src-tauri/src/utils.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index be67035..a543ca9 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -16,27 +16,31 @@ use tauri::AppHandle; use tauri::Manager; use tauri_plugin_clipboard_manager::ClipboardExt; +/// Sends a paste command (Cmd+V or Ctrl+V) using platform-specific virtual key codes. +/// This ensures the paste works regardless of keyboard layout (e.g., Russian, AZERTY, DVORAK). fn send_paste() -> Result<(), String> { - // Determine the modifier key based on the OS + // Platform-specific key definitions #[cfg(target_os = "macos")] - let modifier_key = Key::Meta; // Command key on macOS - #[cfg(not(target_os = "macos"))] - let modifier_key = Key::Control; // Control key on other systems + let (modifier_key, v_key_code) = (Key::Meta, 9); + #[cfg(target_os = "windows")] + let (modifier_key, v_key_code) = (Key::Control, 0x56); // VK_V + #[cfg(target_os = "linux")] + let (modifier_key, v_key_code) = (Key::Control, 47); let mut enigo = Enigo::new(&Settings::default()) .map_err(|e| format!("Failed to initialize Enigo: {}", e))?; - // Press both keys + // Press modifier + V enigo .key(modifier_key, enigo::Direction::Press) .map_err(|e| format!("Failed to press modifier key: {}", e))?; enigo - .key(Key::Unicode('v'), enigo::Direction::Press) + .key(Key::Other(v_key_code), enigo::Direction::Press) .map_err(|e| format!("Failed to press V key: {}", e))?; - // Release both keys + // Release V + modifier (reverse order) enigo - .key(Key::Unicode('v'), enigo::Direction::Release) + .key(Key::Other(v_key_code), enigo::Direction::Release) .map_err(|e| format!("Failed to release V key: {}", e))?; enigo .key(modifier_key, enigo::Direction::Release) From 3614d69bdfd2c7d6e4c9780748523dc1faf40c87 Mon Sep 17 00:00:00 2001 From: CJ Pais Date: Fri, 1 Aug 2025 18:54:01 -0700 Subject: [PATCH 2/2] continue to use unicode on linux --- src-tauri/src/utils.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index a543ca9..e00a4d0 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -21,11 +21,11 @@ use tauri_plugin_clipboard_manager::ClipboardExt; fn send_paste() -> Result<(), String> { // Platform-specific key definitions #[cfg(target_os = "macos")] - let (modifier_key, v_key_code) = (Key::Meta, 9); + let (modifier_key, v_key_code) = (Key::Meta, Key::Other(9)); #[cfg(target_os = "windows")] - let (modifier_key, v_key_code) = (Key::Control, 0x56); // VK_V + let (modifier_key, v_key_code) = (Key::Control, Key::Other(0x56)); // VK_V #[cfg(target_os = "linux")] - let (modifier_key, v_key_code) = (Key::Control, 47); + let (modifier_key, v_key_code) = (Key::Control, Key::Unicode('v')); let mut enigo = Enigo::new(&Settings::default()) .map_err(|e| format!("Failed to initialize Enigo: {}", e))?; @@ -35,12 +35,12 @@ fn send_paste() -> Result<(), String> { .key(modifier_key, enigo::Direction::Press) .map_err(|e| format!("Failed to press modifier key: {}", e))?; enigo - .key(Key::Other(v_key_code), enigo::Direction::Press) + .key(v_key_code, enigo::Direction::Press) .map_err(|e| format!("Failed to press V key: {}", e))?; // Release V + modifier (reverse order) enigo - .key(Key::Other(v_key_code), enigo::Direction::Release) + .key(v_key_code, enigo::Direction::Release) .map_err(|e| format!("Failed to release V key: {}", e))?; enigo .key(modifier_key, enigo::Direction::Release)