Skip to content

Does having hotkeys take an async function make sense? #298

Answered by spyoungtech
trajano asked this question in Q&A
Discussion options

You must be logged in to vote

The callback is simply a callable. Although an async function is technically a callable, calling an async function merely produces a coroutine which must be awaited, so this is likely not what you want to do.

If you must call an async function for your callback, you can use different strategies to work around this, (for example, calling asyncio.run in a regular function) but ultimately, you want to be passing a regular function to ahk.add_hotkey.

Without knowing exactly what your code looks like, a simple solution might be to do something like this:

async def my_async_function():
    print('My async function starting')
    await asyncio.sleep(1)
    print('My async function done')

def my…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by trajano
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants