spyoungtech / ahk

Python wrapper for AutoHotkey with full type support. Harness the automation power of AutoHotkey with the beauty of Python.
MIT License
858 stars 65 forks source link

Adding a callback to an async function for asyncahk #343

Closed Apprisco closed 6 days ago

Apprisco commented 2 weeks ago

Checked the documentation

describe your feature request

ahk.add_hotkey('MButton',callback=self.skip()) I have tried multiple different methods to no avail. All give an error while the closest i've gotten is below.

 Traceback (most recent call last):
  File "C:\Users\Andrew\Anaconda3\envs\Trove\lib\threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "C:\Users\Andrew\Anaconda3\envs\Trove\lib\threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Andrew\Anaconda3\envs\Trove\lib\site-packages\ahk\_hotkey.py", line 299, in dispatcher
    assert hot_thing.callback is not None
AssertionError
def skip(self):
    asyncio.create_task(hi())

If I try to do an async skip function here, it doesn't work at all.

spyoungtech commented 2 weeks ago

Try: callback=self.skip (not self.skip())

spyoungtech commented 6 days ago

If you still need help, feel free to open another issue. Closing this as stale.