简体   繁体   中英

How can I tell if a certain key was pressed in Python?

import sys

print (sys.platform)
print (2 ** 100)
input('press Enter to exit')

Suppose I wanted to use the number 1 as the button that must be pressed to exit. How would I go about doing this?

Something like this?

http://mail.python.org/pipermail/python-list/1999-October/014262.html

Not so clean, but doable.

If you're building a command line app, why not use one of the libraries that help you build one.

For example:

Something like this will do what you want:

while(raw_input('Press "1" to exit.') != '1'):
    pass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM