On AutoHotKey I do something like this using SuspendKeys to turn on or off the script of a list of shortcuts.
Code: Select all
ifenabled := 0
SuspendKeys: ; by default, this app is suspended. And when it's called by ^+!F1, it will be activated.
Suspend
if (ifenabled = 0) {
ifenabled := 1
TrayTip
TrayTip, % "The app", % "Desabled", , 16
} else {
ifenabled := 0
TrayTip
TrayTip, % "The app", % "Enabled", , 16
}
Return
^+!F1:: ; control + shift + alt + F1
Suspend, Permit
Return
ChatGPT showed me this code. Is it the best way? I like AutoHotKeys SuspendKeys because it truly turns off the shortcuts!
Thanks!
Code: Select all
import keyboard
# Global variable to track the active state of the script
active = True
def toggle_activation():
global active
active = not active
print("Script is now", "active" if active else "inactive")
def take_screenshot():
if active:
print("Taking screenshot...") # Replace this with your screenshot logic
def perform_task():
if active:
print("Performing task...") # Replace this with your task logic
def main():
# Listen for Ctrl+J key combination to toggle activation
keyboard.add_hotkey('ctrl+j', toggle_activation)
# Listen for other key combinations to perform actions
keyboard.add_hotkey('x', take_screenshot)
keyboard.add_hotkey('z', perform_task)
print("Script is now active")
keyboard.wait() # Wait for keyboard events indefinitely
if __name__ == "__main__":
main()