I am writing a Python script wherein everytime a key is pressed, a sound is played. I am using the Winsound module to play the sound, and I want something like this:
import winsound
while True:
if any_key_is_being_pressed: # Replace this with an actual if statement.
winsound.PlaySound("sound.wav", winsound.SND_ASYNC)
# rest of the script goes here...
However, I don't want the "While True" block pausing the script when it is being run. I want it to run in the background and let the script carry on being executed, if this is even possible in Python.
Perhaps I am barking up the wrong tree and don't need a while true; if there is any way to play sound when any keyboard key is pressed, then please tell me.
Thank you.