Key Bindings in Command Prompt with Java?

我怕爱的太早我们不能终老 提交于 2019-12-11 10:37:59

问题


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?


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




回答2:


I think CTRL+C should stop your program.



来源:https://stackoverflow.com/questions/7487175/key-bindings-in-command-prompt-with-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!