Преглед изворни кода

Added help and made all keybinds customizeable

Activator and Help are customizable, and currently can clash

No attempts have been made at what needs shift to be "reached" for
output or input (Like the new 'Help' being '?', the macro sees "/",
under-the-hood it's "shift+/" == "?")
Apollo пре 4 месеци
родитељ
комит
535d0c3212
2 измењених фајлова са 50 додато и 7 уклоњено
  1. 17 1
      example_profile.toml
  2. 33 6
      tyrell.py

+ 17 - 1
example_profile.toml

@@ -4,17 +4,33 @@
 # Use '{name}' to emit profile name (the file name)
 placeholder_name = false
 
-# Required Features
+# Default Features
 
 # Tick speed
 # Value in milliseconds
 # Defaults to Minecraft's Tick speed (20 ticks per second, 50 ms)
+#
+# This can't be overridden
 tick = 50
 
 # Delay in-between keys
 # Value in milliseconds
+#
+# Can be overridden per keybind
 delay = 50
 
 # Hold delay of each key
 # Value in milliseconds
+#
+# Can be overridden per keybind
 hold = 20
+
+# What is the key to activate/deactivate macro
+# This value should be adjusted as needed
+#
+activator = "`"
+
+# What is the key to redisplay "help"
+# Should be adjusted as needed (Might not work because of shift and ctrl modifiers)
+#
+helper = "?"

+ 33 - 6
tyrell.py

@@ -16,7 +16,7 @@ except ImportError:
     exit()
 
 from pyautogui import mouseDown as mouse_down, mouseUp as mouse_up
-from keyboard import press as key_down, release as key_up, on_release as keyboard_hook
+from keyboard import press as key_down, release as key_up, on_release as keyboard_hook, KeyboardEvent
 # Not entirely sure why this doesn't work
 #from mouse import press as mouse_down, release as mouse_up, click as mouse_press, move as mouse_move
 
@@ -143,6 +143,8 @@ class Tyrell():
     hold: int
     def __init__(self, profile_name: str):
         self.profile = {
+            "activator": "`",
+            "helper": "?",
             "delay": 50,
             "hold": 20,
             "tick": 50,
@@ -160,6 +162,10 @@ class Tyrell():
                     print(err)
                     exit()
                 self.profile = t
+                if "activator" not in self.profile:
+                    self.profile["activator"] = "`"
+                if "helper" not in self.profile:
+                    self.profile["helper"] = "?"
                 if "hold" not in self.profile:
                     self.profile["hold"] = 20
                 if "delay" not in self.profile:
@@ -247,22 +253,38 @@ class Tyrell():
             if act.tick():
                 act.do(self.delay, self.hold)
 
-    def callback(self, event):
+    def callback(self, event: KeyboardEvent):
         key_name = event.name
-        if key_name == "`":
+        if key_name == self.profile["activator"]:
             if self.toggle():
                 print_ok("ON")
             else:
                 print_ok("OFF")
         elif self.toggled:
-            if key_name in self.keybinds:
+            #print(f"Name:      {event.name}")
+            #print(f"Code:      {event.scan_code}")
+            #print(f"Modifiers: {event.modifiers}")
+            if self.profile["helper"] == "?" and "shift" in event.modifiers and event.name == "/" or key_name == self.profile["helper"]:
+                print_ok(f"{int(1000 / self.profile['tick'])} ticks per second ({self.profile['tick']} ms per tick)")
+                print_ok(f"Name placeholder: {self.profile['placeholder_name']}")
+                print_warn(f"{self.profile["activator"]} -> Activate/Deactivate")
+                print_warn(f"{self.profile["helper"]} -> Displays Help")
+                for key in self.keybinds:
+                    act = self.keybinds[key]
+                    if act.max_delay == 0 and act.toggled:
+                        print_info(f"{key} -> {act.kind}")
+                    else:
+                        print_info(f"{key} -> {act.kind} = {act.toggled}")
+                print_ok("Please use " + style("CTRL+C", fg="bright_yellow") + " to stop")
+            elif key_name in self.keybinds:
                 act = self.keybinds[key_name]
                 if act.max_delay == 0 and act.toggled:
                     print_info(f"{key_name} -> {act.kind}")
                     act.do(self.delay, self.hold)
                 else:
                     print_info(f"{key_name} -> {act.kind} = {act.toggle()}")
-                self.toggle()
+            self.toggle()
+            print_ok("OFF")
 
     async def background(self):
         while True:
@@ -289,6 +311,10 @@ if __name__ == "__main__":
         print_err("Missing 'keys' directory")
         print_info("(Might want some keybinds)")
         exit()
+    print_ok(f"{int(1000 / ty.profile['tick'])} ticks per second ({ty.profile['tick']} ms per tick)")
+    print_ok(f"Name placeholder: {ty.profile['placeholder_name']}")
+    print_warn(f"{ty.profile["activator"]} -> Activate/Deactivate")
+    print_warn(f"{ty.profile["helper"]} -> Displays Help")
     for ent in listdir("keys"):
         if ent.startswith(".") or not ent.endswith(".toml") or isdir(ent):
             continue
@@ -298,7 +324,7 @@ if __name__ == "__main__":
                 ty.add_action(t["keybind"], Action(t["kind"], extra=t, delay=t["duration"]))
             else:
                 ty.add_action(t["keybind"], Action(t["kind"], extra=t))
-            print(f"{t['keybind']} -> {t['kind']}")
+            print_info(f"{t['keybind']} -> {t['kind']}")
     if len(ty.keybinds) == 0:
         print_err("Missing keybinds")
         print_info("(Might want some keybinds, place them in a 'keys' directory)")
@@ -306,6 +332,7 @@ if __name__ == "__main__":
         exit()
     ty.enable(all_notickers=True)
     ty.disable()
+    print_ok("Please use " + style("CTRL+C", fg="bright_yellow") + " to stop")
     try:
         run(ty.mainloop())
     except KeyboardInterrupt: