How to do “hit any key” in python?

后端 未结 7 1835
予麋鹿
予麋鹿 2020-12-01 09:00

How would I do a \"hit any key\" (or grab a menu option) in Python?

  • raw_input requires you hit return.
  • Windows msvcrt has getch() and getche().
  • <
7条回答
  •  日久生厌
    2020-12-01 09:39

    on linux platform, I use os.system to call /sbin/getkey command, e.g.

    continue_ = os.system('/sbin/getkey -m "Please any key within %d seconds to continue..." -c  10')
    if continue_:
       ...
    else:
       ...
    

    The benefit is it will show an countdown seconds to user, very interesting :)

提交回复
热议问题