-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft.py
266 lines (258 loc) · 9.97 KB
/
ft.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/bin/python3
#
# faketyper, (C) 2022/23 lasermtv07
# this programs comes with ABSOLUTELY NO WARRANTY, including warranty implied by merchability
# released under the GNU General public licence, version 3.0 (via file attached to repository)
# this program is free as in freedom, feel free to modify and redistriute it
import sys
import os.path
import typer
import time
import random
#---help for all commands
H_RUN="rm @r -k -d -b -w -c -f -r <speed> <errors> <string> <error characters*>"
VERSION="minor 1.1.1"
history=[]
all_commands=["run","r","help","h","version","v","ti","t"]
def separ(string):
return "¬".join(string.split())
kb_en=[['`','1','2','3','4','5','6','7','8','9','0','-','='],
['q','w','e','r','t','y','u','i','o','p','[',']','\ '],
['a','s','d','f','g','h','j','k','l',';','"','ENTER'],
['z','x','c','v','b','n','m',',','.','/',' SHIFT']
]
kb_cs=[[';','+','ě','š','č','ř','ž','ý','á','í','é','=','´'],
['q','w','e','r','t','z','u','i','o','p','ú',')','¨ '],
['a','s','d','f','g','h','j','k','l',';','"','ENTER'],
['z','x','c','v','b','n','m',',','.','/',' SHIFT']
]
kb_ru=[['§','1','2','3','4','5','6','7','8','9','0','-','='],
['й','ц','у','к','е','н','г','ш','щ','з','х','ъ','\ '],
['ф','ы','в','а','п','р','о','л','д','ж','э','ENTER'],
['я','ч','с','м','и','т','ь','б','ю','.',' SHIFT']
]
kb_su=[['ё','1','2','3','4','5','6','7','8','9','0','+','´'],
['q','w','e','r','t','y','u','i','o','p','å','¨','/ '],
['a','s','d','f','g','h','j','k','l','ö','ä','ENTER'],
['z','x','c','v','b','n','m',',','.','-',' SHIFT']
]
def tips(sw):
tip=["use -s when typing the help command for shortened version"
,"when you always forget syntax of a command, just display shortened help",
"hello. Have (imaginary) 0.05USD for using my program",
"this command has esentially has no point rn, its for the future",
"use v -c to show the changelog",
"now on linux",
"the syntax of the run command is: run [/k] [/d] [/b] [/w] <speed> <errors> <string> <error characters*>"]
if not "a" in sw: print("The tip of today is: " + str(tip[random.randint(0,len(tip)-1)]))
else:
print("List of all tips:")
for r in tip:
print(" -" + r)
def help(sw,args):
if "s" in sw:
print(f'''
HELP - SHORT
============
<{ VERSION }>
{ H_RUN }
help -s
version -c
tip -a
*u can use either the windows style or the linux style switch writing''')
else:
print(f'''
========
= HELP =
========
<{ VERSION }>
Report all bugs you find via github issues and I'll love you <3
COMMANDS*:
run**: run { H_RUN }
-k hides the onscreen keyboard
-d disables the use of capital letters. Legacy function, /doesnt work anymore - change of code structure/
-b writes out the typed string after typing finishes
-w disables 3sec wait before typing starts
-t makes the program read input string from a .txt file
instead of the string typed into command
-s disables the use of keyboard aliases; List here:
- "■" or "¦".. Backspace
- "^".. Space
- "¬"***.. Newline
-l writes the text in an endless loop
-e - Newlines with every space
-c sets the keyboard layout to Czech
-f sets the keyboard layout to Finnish
-r sets the keyboard layout to Russian
<speed> typing speed, in characters per seconds
<errors> probability of error appearing in the text, 0-100, 100 for no errors
<string> the text that will be typed out
<error characters*> list of characters to be replaced by - optional
help: help @h -s - displays this help
-s show shorter version of this help
version: version @v -c
-c prints more detailed version of version changelog
tip: tip @t -a - displays a random tip
-a prints the list of all tips existing
FOOTNOTES:
-* - program can sometimes run slow, especially
for the first time if the libraries arent loaded or if
you set too big speed. Disable keyboard projection, that might help
-** - you can stop the run with the esc key
-*** - presses space, cant have -s in command
---
Released under the GNU General Public Licence
''')
def version(sw,args):
if "c" in sw:
print(f'''
=========
=VERSION=
=========
Version: { VERSION }
Codename: Uhh.. full release i guess?
Release date: 4/11/23 (DD/MM/YY)
CHANGELOG:
MINOR:
- removed dependency on the keyboard package
- changes in notes
- added --help to comply with GNU standards
---
Released under the free GNU General Public Licence, version 3
Feel free to redistribute the program, including modification and sale,
under the condition that you'll keep it free for all other users.
For a program to be free it must follow these 4 specification, as specified by RMS:
(0) Users have freedom to USE the program
(1) Users have access to the SOURCE CODE
(2) Users can REDISTRIBUTE the unmodified program
(3) Users can REDISTRIBUTE modified program
More info on the GNU project website, www.gnu.org
Have fun :)''')
else:
print(f'''Version: { VERSION }
Full release, please report bugs on Github. Use version -c for more info
or help for help
---
Released under the free GNU General Public Licence, version 3
Feel free to redistribute the program, including modification and sale,
under the condition that you'll keep it free for all other users.
visit www.gnu.org or type version -c for more info''')
tips("")
def run(sw,args):
lw=False
disable_bp=True
kb=[['`','1','2','3','4','5','6','7','8','9','0','-','='],
['q','w','e','r','t','y','u','i','o','p','[',']','\ '],
['a','s','d','f','g','h','j','k','l',';','"','ENTER'],
['z','x','c','v','b','n','m',',','.','/',' SHIFT']
]
wr=args[2]
if "t" in sw:
try:
f=open(args[2],'r')
wr=f.read()
f.close()
except:
print("Error: error loading the file")
exit()
if "c" in sw:
kb=kb_cs
elif "f" in sw:
kb=kb_su
elif "r" in sw:
kb=kb_ru
vol=' '
onscreen_kb=1
use_cap=1
write_out=0
if "s" in sw:
disable_bp=False
if "k" in sw:
onscreen_kb=0
if "d" in sw:
use_cap=0
if "b" in sw:
write_out=1
if "l" in sw:
lw=True
if "e" in sw:
wr=separ(wr)
if args[0].isnumeric()!=True:
print("Error:run command:wrong input type (speed)")
if args[1].isnumeric()!=True and int(args[1])<101:
print("Error:run command:wrong input type (errors)")
if "w" not in sw:
print("wait 3 seconds")
time.sleep(3)
try: vol=args[3]
except: vol=' '
try: typer.typer(wr,int(args[0]),int(args[1]),vol,onscreen_kb,use_cap,write_out,kb,disable_bp,lw)
except Exception as e: print("Error: Python error: " + str(e) + "\nPlease report this report to me using GitHub Issues")
class Command:
def __init__(self, cmd, alias, args,vol, execute, syntax):
self.cmd=cmd
self.alias=alias
self.args=args
self.execute=execute
self.vol=vol
self.syntax=syntax
def update(self):
if len(sys.argv)>1 and (self.cmd==sys.argv[1] or self.alias==sys.argv[1]):
receiveargs=[]
out_sw=[]
for x in range(2,len(sys.argv)):
receiveargs.append(sys.argv[x])
for y in receiveargs:
if y[0]=="/" or y[0]=="-":
out_sw.append(y)
for r in out_sw:
while r in receiveargs:
receiveargs.remove(r)
for u in range(len(out_sw)):
if "/" in out_sw[u] or "-" in out_sw[u]:
out_sw[u]=out_sw[u][1]
#print(str(len(receiveargs)) + str(receiveargs))
if len(receiveargs)==self.args or len(receiveargs)>self.args:
#if "$debug" in receiveargs: print(receiveargs)
exec(self.execute)
history.append(self.cmd)
#print(history)
else: print("Error: Wrong arguments: " + self.syntax)
if len(sys.argv)==1:
version([],0)
if "--help" in sys.argv:
print(f'''
Usage: ft run [OPTIONS] SPEED ERR_COUNT STRING ERR_CHARACTERS*
ft help [OPTIONS]
ft version [OPTIONS]
ft tip [OPTIONS]
Fakes typing STRING on keyboard with SPEED and voluntary ERRORS configured with ERR_COUNT and ERR_CHARACTERS
Options:
run -k hides onscreen keyboard
-d Dont use, legacy feature
-b writes out the typed string after typing finishes
-w stops 3s wait before typing
-t read STRING from a .txt file
-s disable keyboard aliases (¦.. backspace; ^.. space; ¬.. newline)
-l wrotes in endless Loop
-e newlines with every space
-c use Czech kb layout
-f use Finnish kb layout
-r use Russian kb layour
help -s shortened
version -c show changelog
tip -a write all
---
(c) lasermtv07, 2023
released under the GNU GPL licence
''')
exit()
r=Command("run", "r", 3,1,'run(out_sw,receiveargs)',H_RUN)
r.update()
v=Command("help", "h", 0,0,'help(out_sw,0)',"help -s")
v.update()
x=Command("version", "v", 0,0,'version(out_sw,0)',"version -c")
x.update()
z=Command("tip", "t", 0,0,'tips(out_sw)',"tip -a")
z.update()
if len(sys.argv)>1 and sys.argv[1] not in all_commands: print("Error: Unknown command")