Skip to content

fix(computer): use clipboard for all text input on macOS to avoid IME issues#2015

Merged
quanru merged 3 commits intomainfrom
fix/computer-macos-ime-input
Feb 14, 2026
Merged

fix(computer): use clipboard for all text input on macOS to avoid IME issues#2015
quanru merged 3 commits intomainfrom
fix/computer-macos-ime-input

Conversation

@quanru
Copy link
Collaborator

@quanru quanru commented Feb 14, 2026

Summary

  • On macOS, always use clipboard paste (Cmd+V) for text input instead of AppleScript keystroke, which sends characters through the active input method
  • This fixes two IME-related issues:
    1. Character loss: typing "http" via keystroke with Chinese IME active could result in "htp" due to the IME consuming some keystrokes
    2. Garbled text: English input gets interpreted as pinyin, producing mixed Chinese/English like "i will过拖O萨卡tomorrow" instead of "i will过拖O萨卡tomorrow"

Root Cause

typeStringViaAppleScript uses AppleScript's keystroke command which simulates key-by-key input. These keystrokes pass through the system's active input method. When a Chinese (or other non-English) IME is active, the keystrokes are intercepted and processed as IME input rather than direct character insertion.

Fix

Changed smartTypeString() on macOS to always use typeViaClipboard(), which writes text to the clipboard and simulates Cmd+V. Clipboard paste completely bypasses the IME pipeline, making it immune to input method state.

Test plan

  • Unit tests pass (npx nx test @midscene/computer -- tests/unit-test/input-strategy.test.ts)
  • Manual test: with Chinese IME active, input ASCII text like "https://google.com" — should appear correctly without character loss
  • Manual test: with Chinese IME active, input mixed text — should work correctly

… issues

AppleScript keystroke sends characters through the active input method,
which causes character loss and garbled text when Chinese IME is active.
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 14, 2026

Deploying midscene with  Cloudflare Pages  Cloudflare Pages

Latest commit: 540a8e1
Status: ✅  Deploy successful!
Preview URL: https://db64aec0.midscene.pages.dev
Branch Preview URL: https://fix-computer-macos-ime-input.midscene.pages.dev

View logs

… on all platforms

IME interference affects all platforms (Windows/Linux have similar Chinese IME issues),
so there's no need to distinguish between ASCII and non-ASCII text.
@quanru quanru force-pushed the fix/computer-macos-ime-input branch from 9094352 to 99626cb Compare February 14, 2026 05:43
…negation

The previous prompt "whether there is no logo1" with an image that IS on
the page confused AI models. Changed to use an image (Google logo) that
is NOT on the GitHub page, with a straightforward positive question.
@quanru quanru merged commit 58a274e into main Feb 14, 2026
9 checks passed
@quanru quanru deleted the fix/computer-macos-ime-input branch February 14, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants