How to detect ESCape keypress in Python?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am running a process in a command window (Windows 7, Python 3.1) where I would like the user to abort the process by pressing the ESCape key. However, pressing the ESCape key doesn't appear to do anything :-(, the loop never breaks. I have also tried running the script from within my IDE (Wing), but again, the loop cannot be interrupted. The following is a stripped-down version of my proof-of-concept test... import msvcrt import time aborted = False for time_remaining in range(10,0,-1): # First of all, check if ESCape was pressed if msvcrt