Closed YI8it closed 10 months ago
There's no builtin or intended way to stop block_forever
-- but you could use ctrl+c to trigger a keyboard interrupt, which will break the loop.
try:
ahk.block_forever()
except KeyboardInterrupt:
pass
print('done blocking')
Beyond this, something like you've implemented would also work, but there's no builtin functionality for this. There is a plan to implement something like exit_app
, but it won't stop block_forever
.
As a possible alternative to what you've implemented, you could use key_wait
to block until a specific key is pressed.
No wonder I couldn't find it then =) Could I just change the definition from async def block_forever(self) -> NoReturn: to async def block_forever(self, run=True) -> NoReturn: and then pass 'False' when I want to terminate it?
Hmm. I'm not sure that makes much sense in the context of asyncio, or maybe I'm not fully understanding the meaning. In any case, the block_forever
methods are mostly there as a very simple convenience. I don't think we plan to add any functionality for interrupting the 'block forever' state.
But if you come up with a novel idea that may be useful to other users, feel free to share it in discussions or open a pull request :)
Hi! I just found this wrapper and hope to have much fun with it. Good initiative! =) I can't seem to figure out one thing though: what method has the opposite effect to "block_forever()"? That is, how can I stop "block_forever()" and let the script exit? I couldn't find anything in the documentation.
Here's what I was hoping to do:
I tried without "block_forever()" and with my own sleep function:
This code needs more CPU-cycles than your "block_forever()", though.