mirror of
https://github.com/krislamo/MacroMC
synced 2024-11-09 23:30:35 +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 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()
|
||||||
|
Loading…
Reference in New Issue
Block a user