You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.7 KiB
50 lines
1.7 KiB
4 years ago
|
import pyautogui
|
||
|
import time
|
||
|
import sys
|
||
|
import argparse
|
||
|
import json
|
||
|
__author__ = 'm3x1m0m'
|
||
|
|
||
|
class LearnerError(RuntimeError):
|
||
|
def __init__(self, imsg):
|
||
|
self.msg = imsg
|
||
|
|
||
|
class c_learner:
|
||
|
def __init__(self, fname):
|
||
|
self.fname = fname
|
||
|
self.__read_settings()
|
||
|
def __read_settings(self):
|
||
|
with open(self.fname, "r") as rf:
|
||
|
self.settings = json.load(rf)
|
||
|
def __write_settings(self):
|
||
|
with open(self.fname, "w") as wf:
|
||
|
json.dump(self.settings, wf, indent=4, sort_keys=True)
|
||
|
def __wait(self, period):
|
||
|
for t in range(0, period):
|
||
|
print("{}".format(period-t))
|
||
|
time.sleep(1.0)
|
||
|
def button(self, which):
|
||
|
if not which in ["backward", "forward"]:
|
||
|
raise LearnerError("Wrong button type!")
|
||
|
print("Go to the {} button".format(which))
|
||
|
self.__wait(5)
|
||
|
currentMouseX, currentMouseY = pyautogui.position()
|
||
|
print("x>{} y>{}".format(currentMouseX, currentMouseY))
|
||
|
self.settings["buttons"][which] = (currentMouseX, currentMouseY)
|
||
|
self.__write_settings()
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
parser = argparse.ArgumentParser(description="I don't like J.")
|
||
|
parser.add_argument("-f","--file", help="JSON file where settings are stored.", required=True)
|
||
|
parser.add_argument("-a", "--forward", help="Store forward button position.", action="store_true")
|
||
|
parser.add_argument("-b", "--backward", help="Store backward button position.", action="store_true")
|
||
|
# Parse
|
||
|
args = parser.parse_args()
|
||
|
|
||
|
if len(args.file) > 0:
|
||
|
pupil = c_learner(args.file)
|
||
|
if args.forward:
|
||
|
pupil.button("forward")
|
||
|
if args.backward:
|
||
|
pupil.button("backward")
|