Detect a key press in console

后端 未结 2 755
迷失自我
迷失自我 2020-12-03 22:08

I want to execute a certain function when a user presses a key. This will be run in the console, and the code is in Java. How do I do this? I have almost zero knowledge of k

2条回答
  •  [愿得一人]
    2020-12-03 22:45

    You can't detect an event in the command line environment. You should provide a GUI, and then you can use the KeyListener class to detect a keyboard event.

    Alternatively you can read commands from standard input and then execute a proper function.

提交回复
热议问题