diff --git a/desktop/src-tauri/src/inject.rs b/desktop/src-tauri/src/inject.rs index b592c34..9fcf450 100644 --- a/desktop/src-tauri/src/inject.rs +++ b/desktop/src-tauri/src/inject.rs @@ -57,10 +57,18 @@ pub fn inject_text(text: &str) -> Result<(), String> { #[cfg(not(target_os = "macos"))] let modifier = Key::Control; + // 粘贴键 V: + // macOS 用物理键码 9(kVK_ANSI_V),直接走 CGEvent,避开 enigo 对 + // Key::Unicode 的键盘布局查询——那条路径调 TSMGetInputSourceProperty, + // 该 API 必须在主线程执行,在 tokio 后台线程上调用会触发断言崩溃 + // (macOS 15/26 收紧了主线程校验)。物理键码与布局无关,粘贴恒为此键位。 + #[cfg(target_os = "macos")] + let paste_key = Key::Other(9); + #[cfg(not(target_os = "macos"))] + let paste_key = Key::Unicode('v'); + enigo.key(modifier, Direction::Press).map_err(|e| e.to_string())?; - enigo - .key(Key::Unicode('v'), Direction::Click) - .map_err(|e| e.to_string())?; + enigo.key(paste_key, Direction::Click).map_err(|e| e.to_string())?; enigo .key(modifier, Direction::Release) .map_err(|e| e.to_string())?;