I want a simple script to stay running in the background. It currently looks like this:
import keyboard
while True:
keyboard.wait('q')
keyboard.send('ctrl+6')
Now, this works already (When q is pressed, it also presses ctrl+6), but I guess there has to be a more efficient way of keeping a program running, so it can act on input.
I would rather not use an infinite while loop.
I'm on Windows
Thanks :)
time.sleep(0.025)or something similar to not hog your CPU tho (unlesskeyboard.wait()is a blocking call, then it doesn't matter. And perhaps implement a event-driven trigger so the actions isn't depending on the time between sleeps/loops (for instance,import selectdoes this). But a while loop is one of the most efficient ways to keep something alive while waiting for a condition.