how terminate console(not Ctrl-C)

N

NoName

Is it possible to interrupt loop (program) by pressing Q key like Ctrl-
C?
how can i hook user's keypress while program running?

thnx
 
O

oj

Is it possible to interrupt loop (program) by pressing Q key like Ctrl-
C?
how can i hook user's keypress while program running?

thnx

There's a quite complicated example here:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/203830

But it seems to just boil down to fiddling around with tty, and then
using select to read from sys.stdin to detect a keypress, and then
taking the appropriate action.

This will be different on Windows. If you really need this, it might
be worth looking for a library that will make key press detection
trivial. For example, this sort of thing is easy with pygame.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top