1
0
mirror of https://github.com/krislamo/MacroMC synced 2024-12-16 09:00:36 +00:00

Install global event hook for toggle

This commit is contained in:
Kris Lamoureux 2020-06-19 16:18:31 -04:00
parent 4c01cf6136
commit 68f5acca7f
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925

View File

@ -18,22 +18,36 @@
import keyboard import keyboard
import pyautogui import pyautogui
enabled = False toggleable = True
state = False
while True: def main(event):
toggled = keyboard.is_pressed('z') global toggleable
global state
if toggled: # Macro hotkey pressed
if enabled: if event.name == 'z':
print("Macro disabled.") # Toggle
enabled = False if event.event_type == 'down':
else:
print("Macro enabled.")
enabled = True
if toggled and not enabled: # Disable macro
if toggleable and state:
print("Toggle disabled")
state = False
pyautogui.mouseUp(0,0) pyautogui.mouseUp(0,0)
#pyautogui.keyUp('w') #keyboard.release('w')
elif enabled: # Enable macro
elif toggleable and not state:
print("Toggle enabled")
state = True
pyautogui.mouseDown(0,0) pyautogui.mouseDown(0,0)
#pyautogui.keyDown('w') #keyboard.press('w')
toggleable = False
# Toggleable again
elif event.event_type == 'up':
toggleable = True
keyboard.hook(main)
keyboard.wait()