我正在编写一个 Python 脚本,其中每次按下一个键,都会播放一个声音。我正在使用 Winsound 模块播放声音,我想要这样的东西:
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...
但是,我不希望“While True”块在脚本运行时暂停它。我希望它在后台运行并让脚本继续执行,如果这在 Python 中是可能的的话。
也许我在叫错树,不需要一段时间是真的;如果按下任何键盘键时有什么方法可以播放声音,那么请告诉我。
谢谢你。