Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python - get key pressing ?

Reply
Thread Tools

Python - get key pressing ?

 
 
Krisztian Kepes
Guest
Posts: n/a
 
      07-03-2003
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





 
Reply With Quote
 
 
 
 
Jiri Barton
Guest
Posts: n/a
 
 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      07-03-2003
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Spring java Controller get correct data from button when "apply"button is clicked but not pressing the <Enter> key albert kao Java 1 04-10-2010 02:54 AM
STRUTS- <html:submit> does not submit on pressing Enter key Megha Vishwanath Java 2 10-02-2009 12:52 PM
Favorite by pressing Key Thaqalain Computer Support 4 08-26-2005 09:28 PM
Postback caused by pressing the "enter" key Cindy ASP .Net 2 03-03-2004 11:02 PM
Get text in TextBox without pressing Enter key mg ASP .Net 5 07-14-2003 02:09 PM



Advertisments