-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype.py
More file actions
62 lines (53 loc) · 3.67 KB
/
type.py
File metadata and controls
62 lines (53 loc) · 3.67 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import time
import random
import argparse
import sys
# Paragraph to be typed
PARAGRAPH = (
"\n\b"
"\n\bDo you think that you may have a future as a writer? If you do, you will want to know about the course that we teach which is designed just for people like you. As you may know, you can earn big money as a writer, even on a part-time basis. We can help you find out if you have writing talent, and if you have, we can help you to develop it.\n\n"
"You do not need to have had four years of college to be able to take our course. We have had quite a few men and women who have had no college training and yet did very well at our school, so do not let this chance slip by. Let us help you to find out if you do have a talent for writing. If you do, then we shall have no trouble teaching you how to write if you will just work as hard as you can.\n\n"
"With our special plan you can progress at your own speed because you will be working in your own home. And you do not have to pay the cost of the course in advance as most other schools demand. We know that you will be better able to pay us after you are through with the course and are earning some money from your writing. None of the other schools that have home-study courses make this offer to their students.\n\n"
"We are sending you a small booket that will tell you all you need to know about our school and about a very short course that we have not mentioned in this letter. Please contact me if you need any further information and I will certainly answer any questions or concerns that you may have about us"
)
def type_with_wpm_range(text, min_wpm=45, max_wpm=55, start_delay=5):
try:
import pyautogui
except Exception:
print("pyautogui is required. Install with: pip3 install pyautogui")
sys.exit(1)
print(f"Place the cursor where you want the text to appear. Starting in {start_delay} seconds...")
time.sleep(start_delay)
words = text.split(" ")
for w in words:
# pick a wpm for this word, convert to seconds per character
wpm = random.uniform(min_wpm, max_wpm)
sec_per_char = 60.0 / (wpm * 5) # 5 chars per "word" standard
for ch in w:
if (random.randint(1, 50) == 10):
backLen = random.randint(1, 5)
for _ in range(backLen):
randchar = random.choice('abcdefghijklmnoprstu ')
pyautogui.write(randchar)
time.sleep(sec_per_char * random.uniform(0.5, 1.4))
for _ in range(backLen):
pyautogui.press("backspace")
time.sleep(sec_per_char * random.uniform(0.1, 0.6))
pyautogui.write(ch)
# small random jitter so timing isn't perfectly uniform
time.sleep(sec_per_char * random.uniform(0.5, 1.4))
# type a space after each word
pyautogui.press("space")
# slight pause between words (a bit longer on average)
time.sleep(sec_per_char * random.uniform(2, 3))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Type a paragraph at 70-80 WPM (approx).")
parser.add_argument("--min", type=float, default=140, help="minimum WPM")
parser.add_argument("--max", type=float, default=160, help="maximum WPM")
parser.add_argument("--delay", type=float, default=5, help="seconds before typing starts")
args = parser.parse_args()
if args.min <= 0 or args.max <= 0 or args.min > args.max:
print("Invalid WPM range.")
sys.exit(1)
# macOS note: you may need to grant Accessibility permission to your terminal/Python app.
type_with_wpm_range(PARAGRAPH, min_wpm=args.min, max_wpm=args.max, start_delay=args.delay)