Want to get the key press event

Discussions

General J2EE: Want to get the key press event

  1. Want to get the key press event (2 messages)

    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.
  2. Want to get the key press event[ Go to top ]

    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.
  3. Want to get the key press event[ Go to top ]

    Take a look at
    java.lang.Runtime#addShutdownHook(java.lang.Thread)