By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

how terminate console(not Ctrl-C)

P: n/a
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
Nov 22 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
oj
On Nov 22, 3:58 am, NoName <zaz...@gmail.comwrote:
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/Coo.../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.
Nov 22 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.