Vishal Gajera
Vishal Gajera

Reputation: 4207

How to stop/terminate java program by pressing Ctrl+C & Ctrl+Alt+Del for window plateform?

I want to terminate my current Java Program's Execution as like,

System.exit(0);

while user press either one of following key-combination from key-board,

 1. Ctrl+C

 2. Ctrl+Alt+Del

I have searched a lot but nothing seems to be correct. if possible then please provide me a fruitful code snippet too.

thank you, :-)

Upvotes: 3

Views: 1771

Answers (2)

Sagar Mal Shankhala
Sagar Mal Shankhala

Reputation: 313

enter image description here

you can terminate the java.exe running process by above code

Upvotes: 0

Amey Jadiye
Amey Jadiye

Reputation: 3154

Seems you are looking for Shutdown hooks in java

Check this answers to cook your code :) How can I "intercept" Ctrl+C in a CLI application?

Upvotes: 1

Related Questions