2016-11-17 79 views
-3

如何让Python 3.5.2等待空格键在Raspbian或OS X上被按下?我一直无法找到任何方法来做到这一点。如果它甚至没有暂停代码,那就没问题,我也不在乎授权。等待特定按键

+0

如果您准备好接受Enter,只需使用'input'。如果没有,做一些研究并阅读例如http://stackoverflow.com/q/983354/3001761。它甚至意味着等待而不暂停代码? – jonrsharpe

+0

http://stackoverflow.com/questions/32671306/how-can-i-read-keyboard-input-in-python – Dalvenjia

回答

0

由于jonsharpe说,你可以使用input这将等待输入,如果你熟悉batch,你会感到宾至如归。

只需使用:

print('Waiting for enter') 
pause = input('') #This will wait until you press enter before it continues with the program 
print('You pressed enter!') 
#Program terminates 

我已经找到了解决方案,适用于Windows,但我找不到任何Raspbian具体的解决方案或OS X.我将继续寻找,如果我发现任何东西,我会更新帖子。