This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
forked from Zuzu-Typ/Input-Recorder
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Irec.py
130 lines (85 loc) · 3.36 KB
/
Irec.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
"""
Input Recorder - Record and play back keyboard and mouse input.
Copyright (C) 2022 Zuzu_Typ
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import os, sys
os.environ["PyPI_REQUIREMENTS_OUTPUT"] = "ON"
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
try:
from requirements import requirements
except IOError:
print("Failed to load requirements.", file=sys.stderr)
try:
import winput
import PIL
assert hasattr(winput, "set_DPI_aware")
except:
sys.exit(-1)
argv_short_to_long_dict = { "h" : "help", "?" : "help" }
kwargs_with_argments = ()
HELP_STRING = """Input Recorder.
Records and plays back macros.
Currently only supports GUI mode.
Usage: irec
"""
def start_command_line_mode(*args, **kwargs):
pass
def start_windowed_mode():
import irec_module.window
def main(*args, **kwargs):
if kwargs.get("help", False):
print(HELP_STRING)
return
if kwargs or args:
start_command_line_mode(*args, **kwargs)
start_windowed_mode()
def process_argv():
argv = sys.argv
kwargs = {}
args = []
if len(argv) > 1:
last_command = None
for arg in argv[1:]:
if len(arg) == 2 and (arg[0] == "-" or arg[0] == "/"):
command_alias = arg[1]
if not command_alias in argv_short_to_long_dict:
raise KeyError("Unknown command line argument {}. Try -h for a list of commands.".format(arg))
if last_command:
raise ValueError("Argument '{}' has no value.".format(last_command))
command = argv_short_to_long_dict[command_alias]
if command in kwargs_with_argments:
last_command = command
else:
kwargs[command] = True
elif len(arg) > 2 and arg.startswith("--"):
command = arg[2:]
if not command in argv_short_to_long_dict.values():
raise KeyError("Unknown command line argument {}. Try -h for a list of commands.".format(arg))
if last_command:
raise ValueError("Argument '{}' has no value.".format(last_command))
if command in kwargs_with_argments:
last_command = command
else:
kwargs[command] = True
else:
if last_command:
kwargs[last_command] = arg
last_command = None
else:
args.append(arg)
if last_command:
raise ValueError("Argument '{}' has no value.".format(last_command))
return (args, kwargs)
if __name__ == "__main__":
args, kwargs = process_argv()
main(*args, **kwargs)