-
Notifications
You must be signed in to change notification settings - Fork 0
/
texttyper.py
31 lines (24 loc) · 864 Bytes
/
texttyper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pyautogui
import pyperclip
import time
class TextTyper:
def __init__(self):
pass
def type_text(self, text):
if text is None:
print("Error, text empty.")
return
try:
# Save the current clipboard content
original_clipboard_content = pyperclip.paste()
# Copy the new text to the clipboard
pyperclip.copy(text)
time.sleep(0.1) # Give a brief moment for the clipboard to update
# Simulate the Ctrl+V keystroke to paste
pyautogui.hotkey('ctrl', 'v')
# Wait a bit to ensure text is pasted before restoring clipboard
time.sleep(0.1)
# Restore the original clipboard content
pyperclip.copy(original_clipboard_content)
except Exception as e:
print(e)