Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Python - get key pressing ? (http://www.velocityreviews.com/forums/t319182-python-get-key-pressing.html)

Krisztian Kepes 07-03-2003 07:36 AM

Python - get key pressing ?
 
Hi !

I want to create an py program what process datas for long time.
But: I want to abort it if I need.
Not with Ctrl+Break !

If I push a key (B, or other), the script must stop his work, and save the result created before.

What I need to catch the keyboard events - without stopping a script ?

Example:

while False:
DoWorkPeriodic()
if KeyEvent=='B':
SaveWork
Stopit

KK






Jiri Barton 07-03-2003 12:16 PM

Re: Python - get key pressing ?
 
http://aspn.activestate.com/ASPN/Coo.../Recipe/203830

Peter Hansen 07-03-2003 02:13 PM

Re: Python - get key pressing ?
 
Krisztian Kepes wrote:
>
> I want to create an py program what process datas for long time.
> But: I want to abort it if I need.
> Not with Ctrl+Break !


Why not? Ctrl+Break, or more typically Ctrl-C, is the de facto standard
approach for terminating a console (non-GUI) application.

> If I push a key (B, or other), the script must stop his work, and save the
> result created before.


In this case, just wrap the code with a "try/except KeyboardInterrupt" and
put your "stop and save" code in the except block. (Note that Ctrl-Break
will bypass this, but Ctrl-C is caught as you would expect.)

Also, when posting questions of this nature it's a good idea explicitly
to specify your platform (Linux, Windows, etc).

-Peter


All times are GMT. The time now is 05:02 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.