如何使用Python3中的键盘打破倒计时?
在某个过程的中间,我有一个倒计时的暂停(对于时间循环。我希望能够用键盘将其打破,以便能够比Countdown更早地完成。 使用Python3(没有Linux root访问)的Python3可能吗?在这种情况下,我可以获取有关按键的一些信息吗?
In the middle of some process I have a pause with countdown (for loop with time.sleep(1) inside). I'd like to be able to break it with keyboard to be able to continue earlier than countdown got finished.
Is it possible with python3 (cross-platform without Linux root access)? Can I get some information about key pressed in this case ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与此问题有关:在(1)python 解决方案时使用Getch
解决方案:使用:使用:使用:
kbhit()
和getch()
: https://docs.python.org/3.10/library/msvcrt.html#console-io工作示例:
请注意,它的反应延迟长达1秒
Related to this question: Use getch in while (1) python
Solution: use
kbhit()
andgetch()
: https://docs.python.org/3.10/library/msvcrt.html#console-i-oWorking example:
Note that it has a reaction delay of up to 1 second
这是我的“跨平台”非常简化的解决方案。
Here is my "cross-platform" very simplified solution.