1

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?

kdabir
  • 9,623
  • 3
  • 43
  • 45
  • 2
    This is strictly shell, terminator emulator, and/or platform independent. There is no completely general answer to this question. – Keith Layne Sep 20 '11 at 14:51

2 Answers2

1

I think CTRL+C should stop your program.

kdabir
  • 9,623
  • 3
  • 43
  • 45
  • I also want to see how to get a custom key binding so that in the future I can have the program execute something else while going through the loop. It looks like I can do it, I'll dig around for maybe an example of using the input stream of the cmd prompt. – priyank patel Sep 20 '11 at 15:06
1

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).

SJuan76
  • 24,532
  • 6
  • 47
  • 87
  • So there is a way for me to have key mappings to command prompt by using the input stream to look for that ctrl+q that I could use to trigger the close of that program. I realize that ctrl+c works this way but I also wanted to see if I could use a different combination. Any clue on what to search for to see an example of this? I've tried key bindings that work in a form, but can't get it working in the command prompt (probably not passing the input stream to the program correctly). – priyank patel Sep 20 '11 at 15:04
  • For a console program, the only way to receive inputs from the keyboard is reading System.in. There is nothing more to it. – SJuan76 Sep 20 '11 at 15:09