1
0
mirror of https://github.com/krislamo/MacroMC synced 2024-09-19 16:40: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
pyautogui.mouseUp(0,0) if toggleable and state:
#pyautogui.keyUp('w') print("Toggle disabled")
elif enabled: state = False
pyautogui.mouseDown(0,0) pyautogui.mouseUp(0,0)
#pyautogui.keyDown('w') #keyboard.release('w')
# Enable macro
elif toggleable and not state:
print("Toggle enabled")
state = True
pyautogui.mouseDown(0,0)
#keyboard.press('w')
toggleable = False
# Toggleable again
elif event.event_type == 'up':
toggleable = True
keyboard.hook(main)
keyboard.wait()