upd keytype for linux

This commit is contained in:
d-chrka 2026-03-19 20:01:03 +01:00
parent 4efa66fc79
commit 460b6356e3
1 changed files with 19 additions and 2 deletions

View File

@ -4,6 +4,8 @@ Hold hotkey to record, release to transcribe and type into active window.
""" """
import json import json
import os import os
import shutil
import subprocess
import threading import threading
import time import time
import tkinter as tk import tkinter as tk
@ -63,7 +65,6 @@ class AppState:
state = AppState.IDLE state = AppState.IDLE
audio_chunks = [] audio_chunks = []
model = None model = None
typer = KeyboardController()
config = {} config = {}
tray_icon = None tray_icon = None
overlay_window = None overlay_window = None
@ -71,6 +72,22 @@ overlay_tk = None
hotkey_listener = 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 ──────────────────────────────────────────────────────── # ── Hotkey via pynput ────────────────────────────────────────────────────────
_MODIFIER_MAP = { _MODIFIER_MAP = {
@ -336,7 +353,7 @@ def stop_and_transcribe():
set_state(AppState.IDLE) set_state(AppState.IDLE)
if text: if text:
time.sleep(0.15) time.sleep(0.15)
typer.type(text) type_text(text)