upd keytype for linux
This commit is contained in:
parent
4efa66fc79
commit
460b6356e3
21
dictate.py
21
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)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue