0

Basically the title, i have a small python script (python 3.9, Windows 10) that i would like to keep running in the background. It is currently listening for keyboard hotkeys and acting like a macro engine. I want it to stay idle, since i use the keyboard module so i doesnt need to call anything, just wait.
I tried a while loop with either pass or sleep in it, but both have downsides, the one with pass using a lot of cpu ressources, and the one with sleep being very unreliable.

Is there any pretty/good practice way of doing this ?

1 Answer 1

1

I would suggest to use some library that does the trick for you.

For example you can try Asyncio:

import asyncio 

loop = asyncio.get_event_loop()
try:
    loop.run_forever()
finally:
    loop.close()

Here's an Asyncio example for keypress.

Sign up to request clarification or add additional context in comments.

1 Comment

Hello, did you have a moment to check my reply? If it was useful for you please consider upvoting it and / or choosing it as final answer. Thanks for your time!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.