From 460b6356e3e611075610f5f1702b1d519d7c0434 Mon Sep 17 00:00:00 2001 From: d-chrka Date: Thu, 19 Mar 2026 20:01:03 +0100 Subject: [PATCH] upd keytype for linux --- dictate.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/dictate.py b/dictate.py index bc600bf..b2e70f4 100644 --- a/dictate.py +++ b/dictate.py @@ -4,6 +4,8 @@ Hold hotkey to record, release to transcribe and type into active window. """ import json import os +import shutil +import subprocess import threading import time import tkinter as tk @@ -63,7 +65,6 @@ class AppState: state = AppState.IDLE audio_chunks = [] model = None -typer = KeyboardController() config = {} tray_icon = None overlay_window = None @@ -71,6 +72,22 @@ overlay_tk = None hotkey_listener = None +def type_text(text): + """Type text into the active window, cross-platform.""" + if os.name == "nt": + KeyboardController().type(text) + return + session = os.environ.get("XDG_SESSION_TYPE", "") + if session == "wayland" and shutil.which("wl-copy"): + subprocess.run(["wl-copy", "--", text], check=False) + time.sleep(0.05) + subprocess.run(["xdotool", "key", "ctrl+v"], check=False) + elif shutil.which("xdotool"): + subprocess.run(["xdotool", "type", "--clearmodifiers", "--", text], check=False) + else: + KeyboardController().type(text) + + # ── Hotkey via pynput ──────────────────────────────────────────────────────── _MODIFIER_MAP = { @@ -336,7 +353,7 @@ def stop_and_transcribe(): set_state(AppState.IDLE) if text: time.sleep(0.15) - typer.type(text) + type_text(text)