add_hotkey ( '#n', callback = go_boom, ex_handler = my_ex_handler ) You can also add an exception handler for your callback: from ahk import AHK ahk = AHK () def go_boom (): raise Exception ( 'boom!' ) def my_ex_handler ( hotkey : str, exception : Exception ): print ( 'exception with callback for hotkey', hotkey, 'Here was the error:', exception ) ahk. Now whenever you press + n, the my_callback callback function will be called in a background thread. block_forever () # not strictly needed in all scripts - stops the script from exiting sleep forever start_hotkeys () # start the hotkey process thread ahk. add_hotkey ( '#n', callback = my_callback ) ahk. Hotkeys can be configured to run python functions as callbacks.įor example: from ahk import AHK def my_callback (): print ( 'Hello callback!' ) ahk = AHK () # when WIN + n is pressed, fire `my_callback` ahk. Non-exhaustive examples of some functions available with this package. mouse_move ( x = 150, y = 150, speed = 10, blocking = True ) # Moves the mouse to x, y taking 'speed' seconds to move print ( ahk. mouse_move ( x = 100, y = 100, blocking = True ) # Blocks until mouse finishes moving (the default) ahk. See also Non-Python dependencies Usage from ahk import AHK ahk = AHK () ahk.
0 Comments
Leave a Reply. |