如何在 Python (2.7 + ) 中等待 ENTER 键?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19374944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:36:00  来源:igfitidea点击:

How to wait for ENTER key press in Python (2.7 + )?

python

提问by Mahi

I would like to know a simple way to wait for a user to press a specific key, like Enter or Escape (but not both), and then execute the code further after sensing the key press.

我想知道一种简单的方法来等待用户按下特定键,如 Enter 或 Escape(但不是两者),然后在感应到按键后进一步执行代码。

采纳答案by Ben

Try:

尝试:

raw_input('Press enter to continue: ')

Or, in Python 3:

或者,在 Python 3 中:

input('Press enter to continue: ')

回答by forefinger

Just use

只需使用

raw_input('Press Enter')

That will print the message and then wait for you to press enter.

这将打印消息,然后等待您按 Enter。