-
Want to get the key press event (2 messages)
- Posted by: I Abbas
- Posted on: September 03 2002 00:43 EDT
Is there any way to find out the key pressed events in Java?? I am not talking about awt classes, i want to use them in my stand alone program. Specifically i want to catch the event of pressing Ctrl+C ( which is used to stop the program ) and execute some manipulations before actually shutting down my program. Any help in this regard is highly appreciated. This feature is actually implemented in J2EE server. When u try to stop the j2ee ( by pressing the ctrl+c key ), it actually catches the key and shuts it down properly.Threaded Messages (2)
- Want to get the key press event by Michael Rasmussen on September 03 2002 01:33 EDT
- Want to get the key press event by Lasse Koskela on September 03 2002 05:48 EDT
-
Want to get the key press event[ Go to top ]
- Posted by: Michael Rasmussen
- Posted on: September 03 2002 01:33 EDT
- in response to I Abbas
Its a console app I am assuming?
So I guess you could just put the code you want to run when you detect ctrl+c in the destroy of your class and it would run when the jvm tries to kill off your app.
Just a thought. -
Want to get the key press event[ Go to top ]
- Posted by: Lasse Koskela
- Posted on: September 03 2002 05:48 EDT
- in response to I Abbas
Take a look at
java.lang.Runtime#addShutdownHook(java.lang.Thread)