2016-11-17 76 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.我將繼續尋找,如果我發現任何東西,我會更新帖子。