From 672ad148fe526b8d6fcdbd6153f57030f67a4ef8 Mon Sep 17 00:00:00 2001 From: Edern Deneuville Date: Fri, 11 Sep 2026 13:22:31 +0200 Subject: [PATCH] Read prompt from clipboard without copying selection --- src/ai_typewriter/clipboard_capture.py | 30 ++++++-------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/src/ai_typewriter/clipboard_capture.py b/src/ai_typewriter/clipboard_capture.py index b12ea37..626f827 100644 --- a/src/ai_typewriter/clipboard_capture.py +++ b/src/ai_typewriter/clipboard_capture.py @@ -1,29 +1,13 @@ from __future__ import annotations -import time - -import keyboard import pyperclip +def capture_clipboard() -> str: + """Return the current clipboard text without modifying it.""" + return pyperclip.paste() or "" + + +# Backward-compatible alias for older imports/tests. def capture_selection(copy_wait_seconds: float = 1.0, restore_clipboard: bool = True) -> str: - previous = pyperclip.paste() - keyboard.send("ctrl+c") - - deadline = time.monotonic() + max(copy_wait_seconds, 0.05) - captured = previous - while time.monotonic() < deadline: - current = pyperclip.paste() - if current != previous: - captured = current - break - time.sleep(0.03) - else: - captured = pyperclip.paste() - - if restore_clipboard: - try: - pyperclip.copy(previous) - except pyperclip.PyperclipException: - pass - return captured or "" + return capture_clipboard()