Skip to content

Hardcoded US-ANSI keycodes break Cmd+V/Cmd+C on Dvorak/Turkish-F layouts, plus KeyInjector vs SelectionCopy clipboard race #341

Open

Description

@Pizzylee001

Summary

Two injection / clipboard bugs in Sources/BlurtEngine/Injection/ and Sources/BlurtEngine/TTS/:

  1. Hardcoded US-ANSI 0x09 / 0x08 breaks paste & copy on non-QWERTY layouts

    • Sources/BlurtEngine/Injection/KeyInjector+SystemActions.swift:89-96 hardcodes virtualKey: 0x09 (kVK_ANSI_V) and virtualKey: 0x08 (kVK_ANSI_C), whereas Command/VoiceCommandKeys.swift:14-17,43-57 already resolves character shortcuts through KeyboardLayout.current().
    • Dvorak: 0x09 is k and 0x08 is j. Every dictation, rewrite, compose, and voice-command type sends ⌘K instead of ⌘V, and 400 ms later restores the clipboard, silently losing the dictated text.
    • Turkish-F: 0x08 is v and 0x09 is c (swapped). Triggering Read Aloud / Ask in an AX-unreadable app calls postCmdC() which sends ⌘V, pasting clipboard contents into the user's document.
  2. Unsynchronized NSPasteboard.general race between KeyInjector (400 ms pendingSettle) and SelectionCopy

    • KeyInjector.swift:224-228 returns from insert() immediately while pendingSettle keeps the transcript on NSPasteboard.general for 400 ms.
    • If the user triggers Read Aloud / Ask / Rewrite in an AX-unreadable app within 400 ms (SelectionCopy.swift:74-105):
      • If ⌘C lands first: SelectionCopy snapshots the transcript as saved, restores the transcript after reading, and pendingSettle later skips its restore because changeCount moved, permanently overwriting the user's original clipboard.
      • If pendingSettle fires mid-poll: SelectionCopy sees ownWriteCount != ownWrites and returns early at line 101 without starting restoreLateCopy, letting the in-flight ⌘C permanently overwrite the restored clipboard.

Suggested Fix

  • Resolve "v" and "c" via KeyboardLayout.current() (with 0x09 / 0x08 fallback).
  • Serialize KeyInjector (write + ⌘V + settle/restore) and SelectionCopy (snapshot + ⌘C + poll + restore) through a shared clipboard coordinator.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions