[Tutor] How to capture 'Ctrl+c' in Python

Andreas Kostyrka andreas at kostyrka.org
Wed Nov 1 12:59:45 CET 2006


Am Mittwoch, den 01.11.2006, 10:14 +0000 schrieb Asrarahmed Kadri:
> 
>  
> Hi folks,
> How can I know that the user has pressed a particular key or c
> combination of keys.. for example 'q' or 'Ctrl-c' ....?

In practice that depends upon your environment. Unix/Linux, MacOS,
Windows, GUI vs. cmdline have all different ways to "read" from the
keyboard.

Ctrl-c OTOH, usually sends the interrupt signal to the process, and as
such can caught via the KeyboardInterrupt exception:

try:
    somework
except KeyboardInterrupt:
    ctrlc_caught

Andreas

>  
> Thanks in anticipation.
>  
> Regards,
>  
> Asrarahmed
>  
>  
> 
> -- 
> To HIM you shall return. 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20061101/254f59fe/attachment.pgp 


More information about the Tutor mailing list