Initial ai typewriter implementation
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
|
||||
import keyboard
|
||||
import pyperclip
|
||||
|
||||
|
||||
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 ""
|
||||
Reference in New Issue
Block a user