Last active
October 1, 2025 03:17
-
-
Save vietvudanh/53b34e2678dd572b88563cd524b4045c to your computer and use it in GitHub Desktop.
send_string_file.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Script to send string to keyboard | |
# INSTALL | |
python -m venv .venv | |
source .venv/bin/activate | |
pip install pyautogui | |
# USAGE | |
1. Change `data_to_send` | |
2. Hover mouse to place where you want to send keystrokes in (Browser/RDP) | |
3. Wait for script to run | |
# WARNING | |
1. Use textedit(MacOS), gedit(Linux), notepad(Windows) to receive text. Do not use SublimeText, VsCode, or IDE. It will auto format/indent => wrong | |
2. Using Linux to send is about 20 times faster than MacOS | |
3. Network matters | |
""" | |
import argparse | |
import time | |
from pathlib import Path | |
import pyautogui | |
parser = argparse.ArgumentParser(description="Process string/single file.") | |
parser.add_argument("--file_name", description="File to send, if not provided then using `data_to_send`") | |
parser.add_argument("--delay", default=3, type=int, description="Delay in seconds") | |
parser.add_argument("--interval", default=0.0005, type=float, description="Interval between keypress in seconds. Need this or will be overloaded") | |
args = parser.parse_args() | |
DELAY_TIME = args.delay | |
data_to_send = '''TEXT TO SEND''' | |
if args.file_name is not None: | |
input_path = Path(args.file_name) | |
if input_path.is_file(): | |
data_to_send = input_path.open("r").read() | |
elif input_path.is_dir(): | |
text_to_send = "" | |
for file in input_path.glob('*.py'): | |
text_to_send += f"""======= {file.name} \n""" | |
text_to_send += file.open("r").read() | |
text_to_send += "\n" | |
data_to_send = text_to_send | |
print(f"Will send {len(data_to_send)} characters after {DELAY_TIME} seconds") | |
pyautogui.countdown(DELAY_TIME) | |
start_time = time.time() | |
pyautogui.click() | |
pyautogui.write(data_to_send, interval=args.interval) | |
end_time = time.time() | |
print("Done!") | |
print(f"Wrote {len(data_to_send)} characters in {end_time - start_time:.2f} seconds") | |
print(f"Speed: {len(data_to_send) / (end_time - start_time):.2f} characters/second") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment