Browse Source

Attempting to get mirror keys working without lag

A small project works... so I'm not sure why Tyrell doesn't

I though maybe it was to use hotkeys, but nope, those won't fire while anything else is pressed

So my initial hook on every event, and process them, does what I want it too, it's just bulky

You don't suppose it's because of the weight of Action (a class/object)?
david 3 months ago
parent
commit
790ce836ae
2 changed files with 60 additions and 4 deletions
  1. 30 0
      _example/keys/example_mirror.toml
  2. 30 4
      tyrell.py

+ 30 - 0
_example/keys/example_mirror.toml

@@ -0,0 +1,30 @@
+
+# Mirrors are currently disabled, due to unwanted latency
+
+# key to toggle
+keybind = "z"
+
+# kind of event
+kind = "mirror"
+
+# Mirror what key
+mirror = "w"
+
+# When mirror is down, so will this
+# When mirror is up, so will this
+#
+# In this case, shift will be held down when w is (only when toggled on)
+write = "shift"
+
+# Or button could be configured
+#
+# For example: right click when w (down when w is, up when w is)
+#button = "right"
+
+# << REQUIRED >>
+
+# This is needed for "mirror" kinds
+# We don't want delays, so make sure you turn everything off!
+#
+delay = 0
+hold = 0

+ 30 - 4
tyrell.py

@@ -100,7 +100,10 @@ class Action():
     def __init__(self, name, kind, extra=None, toggled=False, delay=0):
         self.name = name
         self.kind = kind
-        self.extra = extra
+        if extra is not None:
+            self.extra = extra
+        else:
+            self.extra = {}
         self.toggled = toggled
         self.delay = delay
         self.max_delay = delay
@@ -288,7 +291,7 @@ class Tyrell():
             if act.max_delay == 0 and act.toggled:
                 print_info(f"{key} -> {act.name}")
             else:
-                print_info(f"{key} -> {act.name} = {act.toggled} ({act.delay} ticks)")
+                print_info(f"{key} -> {act.name} = {act.toggled} ({act.max_delay} ticks)")
         print_ok("Please use " + style("CTRL+C", fg="bright_yellow") + " to stop")
 
     def tick(self):
@@ -343,7 +346,22 @@ class Tyrell():
                 print_info(style("OFF", fg="bright_red"))
             return
         if state == "up" or state == "down":
-            print(f"Got: '{mirror_host}' {state}")
+            act = self.keybinds[mirror_host]
+            if act.toggled:
+                if act.extra["write"] != None or len(act.extra["write"]) != 0:
+                    if state == "up":
+                        print(f"'{bind}' -> {act.name} UP")
+                        key_up(act.extra["write"])
+                    elif state == "down":
+                        print(f"'{bind}' -> {act.name} DOWN")
+                        key_down(act.extra["write"])
+                elif act.extra["button"] != None or len(act.extra["button"]) != 0:
+                    if state == "up":
+                        print(f"'{bind}' -> {act.name} UP")
+                        mouse_up(button=act.extra["button"])
+                    elif state == "down":
+                        print(f"'{bind}' -> {act.name} DOWN")
+                        mouse_down(button=act.extra["button"])
             return
         if not self.toggled:
             return
@@ -352,7 +370,15 @@ class Tyrell():
             self.disable()
             print_info(style("OFF", fg="bright_red"))
             return
-        print(f"Got: '{bind}' {state}")
+        act = self.keybinds[bind]
+        if act.toggled:
+            print(f"'{bind}' -> {act.name}")
+            act.do(self.delay, self.hold)
+        elif act.max_delay != 0 or act.kind == "mirror":
+            if act.toggle():
+                print(f"'{bind}' -> {act.name} " + style("ON", fg="bright_green"))
+            else:
+                print(f"'{bind}' -> {act.name} " + style("OFF", fg="bright_red"))
         self.disable()
         print_info(style("OFF", fg="bright_red"))