-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtyper.py
More file actions
124 lines (93 loc) · 3.34 KB
/
typer.py
File metadata and controls
124 lines (93 loc) · 3.34 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import time
import random
import os
from pynput.keyboard import Key, Controller, Listener
running = True
paused = False
length = 0
keyboard = Controller()
def estimate_typing_time(text):
global length
base_time = length * 0.25
sentence_ends = sum(text.count(c) for c in [".", "!", "?", "\n"])
sentence_overhead = sentence_ends * 1.4
commas = text.count(",")
comma_overhead = commas * 0.65
error_overhead = (length * 0.01) * 1.1
total_seconds = base_time + sentence_overhead + comma_overhead + error_overhead
minutes = int(total_seconds // 60)
seconds = int(total_seconds % 60)
return f"-> Estimated writing time: {minutes} min {seconds} sec"
def on_press(key):
global running, paused
if key == Key.esc:
print("\n[!] ESC detected, exiting...")
keyboard.type(".")
running = False
return False
if key == Key.right:
paused = not paused
status = "PAUSED" if paused else "RESUMED"
print(f"\n[i] Typing {status}... (Right arrow key to pause/resume)")
def typing(file_path):
global running, paused, length
if not file_path.lower().endswith('.txt'):
print("The provided file is not .txt!")
return
if not os.path.exists(file_path):
print(f"Error: '{file_path}' file not found.")
return
try:
with open(file_path, 'r', encoding='utf-8') as f:
text = f.read()
except Exception as e:
print(f"\n[!] Error while opening: {e}")
return
length = len(text)
print(f"File loaded: {length} char.")
time.sleep(1)
print(estimate_typing_time(text))
time.sleep(1)
print("Click in the typing field, starting in 10 sec . . .\n\n")
time.sleep(10)
print("Starting. . . Use ESC to EXIT, or the right arrow key to PAUSE/Resume")
listener = Listener(on_press=on_press)
listener.start()
procentLog = 1
for i, char in enumerate(text):
if not running:
break
if paused:
time.sleep(0.5)
continue
delay = random.uniform(0.1, 0.4)
if random.random() < 0.1:
wrong_char = random.choice("asdfghjklyz")
keyboard.type(wrong_char)
time.sleep(random.uniform(0.3, 0.6))
keyboard.press(Key.backspace)
keyboard.release(Key.backspace)
time.sleep(random.uniform(0.2, 0.4))
swap_map={"i": "y", "y": "i"}
if char in [".", "!", "?", "\n"]:
delay += random.uniform(0.8, 2.0)
elif char == ",":
delay += random.uniform(0.4, 0.9)
elif char in swap_map and random.random() < 0.3:
keyboard.type(swap_map[char])
time.sleep(random.uniform(0.5, 1))
keyboard.press(Key.backspace)
keyboard.release(Key.backspace)
time.sleep(random.uniform(0.2, 0.4))
keyboard.type(char)
time.sleep(delay)
procent = round(((i+1)/length) *100)
if procent % 5 == 0 and procent != procentLog:
print(f"Progress: {procent}% | {i}/{length}char", end="\r")
procentLog = procent
else:
print("\n[+] Writing successfull.")
listener.stop()
if __name__ == "__main__":
filename = input("Enter the name of the TXT file (e.g., essay.txt): ")
typing(filename)