priyank patel
priyank patel

Reputation: 13

Key Bindings in Command Prompt with Java?

I have a java program running in a loop in command prompt (I open command prompt and execute a java command). I wanted to setup some key binding (like ctrl+q) so that I could exit the java program while it is running (the program is running through a while loop). Is there anyway to do this? I was trying to use key mappings but wasn't getting it to work. Do custom key mappings not work in command prompt?

Upvotes: 1

Views: 711

Answers (2)

SJuan76
SJuan76

Reputation: 24885

As keith.layne points out, this is OS specific.

For console programs, the OS provides an inputstream to the program. Keys pressed are sent to that inputstream, but if the program does not read them the OS does nothing about it. Also, some special combinations (CTRL-C, by example) are intercepted by the OS and causes it to do certain actions (usually kill the process).

Upvotes: 1

kdabir
kdabir

Reputation: 9868

I think CTRL+C should stop your program.

Upvotes: 1

Related Questions