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:
parent
4c01cf6136
commit
68f5acca7f
42
macromc.py
42
macromc.py
@ -18,22 +18,36 @@
|
||||
import keyboard
|
||||
import pyautogui
|
||||
|
||||
enabled = False
|
||||
toggleable = True
|
||||
state = False
|
||||
|
||||
while True:
|
||||
toggled = keyboard.is_pressed('z')
|
||||
def main(event):
|
||||
global toggleable
|
||||
global state
|
||||
|
||||
if toggled:
|
||||
if enabled:
|
||||
print("Macro disabled.")
|
||||
enabled = False
|
||||
else:
|
||||
print("Macro enabled.")
|
||||
enabled = True
|
||||
# Macro hotkey pressed
|
||||
if event.name == 'z':
|
||||
# Toggle
|
||||
if event.event_type == 'down':
|
||||
|
||||
if toggled and not enabled:
|
||||
# Disable macro
|
||||
if toggleable and state:
|
||||
print("Toggle disabled")
|
||||
state = False
|
||||
pyautogui.mouseUp(0,0)
|
||||
#pyautogui.keyUp('w')
|
||||
elif enabled:
|
||||
#keyboard.release('w')
|
||||
# Enable macro
|
||||
elif toggleable and not state:
|
||||
print("Toggle enabled")
|
||||
state = True
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user