Pit record

pynput Controller.type() scrambles mixed Chinese+English text on macOS; use clipboard paste

pynput.keyboard.Controller.type() on macOS scrambles mixed Chinese+English strings (reordered, English fragments shoved to the end, some CJK dropped) because CJK goes via synthesized Unicode events and ASCII via key events, and the two paths race. Inject via clipboard (pbcopy + Cmd+V) for an atomic insert.

Fast answer

Problem: injecting '打开Claude Code,然后commit一下。' yields '打开ClaudeC,然后一下。odecomit' — reordered, English fragments shoved to the end, some CJK dropped

Root cause: On macOS pynput types CJK characters via synthesized Unicode events and ASCII via key events.

Fix first: Switch text injection from per-character keyboard.type() to clipboard paste: copy the full string via pbcopy, then simulate Cmd+V.

Verify: Inject the same mixed Chinese+English sentence after the change.

Queries this answers

  • pynput Controller.type() scrambles mixed Chinese+English text on macOS; use clipboard paste
  • pynput Controller.type() scrambles mixed Chinese+English text on macOS; use clipboard paste fix
  • pynput Controller.type() scrambles mixed Chinese+English text on macOS; use clipboard paste root cause
  • how to fix pynput Controller.type() scrambles mixed Chinese+English text on macOS; use clipboard paste
  • pynput mixed chinese english text macos clipboard paste
  • pynput mixed chinese english text macos clipboard paste fix
  • macos clipboard paste type scrambles mixed chinese english text pynput
  • macos clipboard paste type scrambles mixed chinese english text pynput fix

Record metadata

Statusverified
Confidencemedium
Created2026-06-21
Updated2026-06-21
Last verified2026-06-21
Affected toolspynput, voice-to-claude
Tagsmacos, pynput, text-injection, unicode, cjk, race-condition, clipboard, voice

Common search queries

  • pynput-mixed-cjk-ascii-type-out-of-order-macos
  • pynput mixed cjk ascii type out of order macos
  • pynput Controller.type() scrambles mixed Chinese+English text on macOS; use clipboard paste
  • pynput Controller.type() scrambles mixed Chinese+English text on macOS; use clipboard paste fix
  • pynput Controller.type() scrambles mixed Chinese+English text on macOS; use clipboard paste root cause
  • macos
  • pynput
  • text-injection
  • unicode
  • race-condition
  • clipboard
  • voice

Symptoms

  • injecting '打开Claude Code,然后commit一下。' yields '打开ClaudeC,然后一下。odecomit' — reordered, English fragments shoved to the end, some CJK dropped
  • pure-English and pure-Chinese strings inject fine
  • only mixed CJK+ASCII text scrambles

Environment

osmacOS
archApple Silicon
languagePython
runtimepynput.keyboard.Controller.type()
versions{"python":"3.12"}
constraintstext injection into a focused input box

Root cause

  • On macOS pynput types CJK characters via synthesized Unicode events and ASCII via key events.
  • The two dispatch paths have different timing and race each other, so a fast mixed-script string arrives interleaved / reordered.

Fix

  1. Switch text injection from per-character keyboard.type() to clipboard paste: copy the full string via pbcopy, then simulate Cmd+V.

    pbcopy <<< "$text"; then synthesize Cmd+V
  2. Rely on the atomic clipboard insert so there is no per-character race.

Verification

  • Inject the same mixed Chinese+English sentence after the change.

    Expected: It appears intact and in correct order.

Workarounds

  • Restore the previous clipboard contents after pasting if clobbering it is a concern.

Anti-patterns

  • Using pynput Controller.type() for mixed CJK+ASCII text on macOS.
  • Adding per-character sleeps to 'fix' ordering instead of switching to an atomic paste.

Sources

  • voice-to-claude daemon debugging session (local-session): local-session:2026-06-21

No matching fix?

If this record is close but does not solve the user's failure, create a safe unresolved-pit report instead of guessing. Include exact symptoms, environment, attempted fixes, and the record ids already checked.