From 3a98afaf188a32d766294af2c0a63069de83a7fc Mon Sep 17 00:00:00 2001 From: Maximilian Stiefel Date: Mon, 23 Nov 2020 16:05:03 +0100 Subject: [PATCH] Forward and backward position learning possible --- JerkyJ.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ settings.json | 12 ++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 JerkyJ.py create mode 100644 settings.json diff --git a/JerkyJ.py b/JerkyJ.py new file mode 100644 index 0000000..9040c46 --- /dev/null +++ b/JerkyJ.py @@ -0,0 +1,49 @@ +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") diff --git a/settings.json b/settings.json new file mode 100644 index 0000000..1b46d08 --- /dev/null +++ b/settings.json @@ -0,0 +1,12 @@ +{ + "buttons": { + "backward": [ + 105, + 198 + ], + "forward": [ + 1073, + 175 + ] + } +} \ No newline at end of file