import os import shutil import subprocess import time def _pynput_type(text): from pynput.keyboard import Controller as KeyboardController KeyboardController().type(text) def type_text(text): """Type text into the active window, cross-platform.""" if os.name == "nt": _pynput_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: _pynput_type(text)