如何让脚本等待按下的键? [英] How to make a script wait for a pressed key?
本文介绍了如何让脚本等待按下的键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的脚本等到用户按下任意键.
我该怎么做?
I want my script to wait until the user presses any key.
How do I do that?
推荐答案
在 Python 3 中使用 input()
:
input("Press Enter to continue...")
在 Python 2 中使用 raw_input()
:
raw_input("Press Enter to continue...")
这只会等待用户按回车键.
This only waits for the user to press enter though.
有人可能想要使用 msvcrt((仅限 Windows/DOS)msvcrt 模块使您可以访问 Microsoft Visual C/C++ 运行时库中的许多函数(MSVCRT)):
One might want to use msvcrt ((Windows/DOS only) The msvcrt module gives you access to a number of functions in the Microsoft Visual C/C++ Runtime Library (MSVCRT)):
import msvcrt as m
def wait():
m.getch()
这应该等待按键.
附加信息:
在 Python 3 raw_input()
中不存在
in Python 3 raw_input()
does not exist
在 Python 2 中 input(prompt)
等价于 eval(raw_input(prompt))
In Python 2 input(prompt)
is equivalent to eval(raw_input(prompt))
这篇关于如何让脚本等待按下的键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文