所以我正在尝试“记录”正在按下的键。问题是当我运行我的代码时,程序只是自动停止并将我送回我可以编码的地方。
我使用Eclipse
import org.jnativehook.keyboard.NativeKeyEvent; import org.jnativehook.keyboard.NativeKeyListener; public class Listener implements NativeKeyListener { public static void main(String[] args) { System.out.print("Program started"); } @Override public void nativeKeyPressed(NativeKeyEvent arg0) { System.out.print("A key was pressed"); } @Override public void nativeKeyReleased(NativeKeyEvent arg0) { // TODO Auto-generated method stub } @Override public void nativeKeyTyped(NativeKeyEvent arg0) { // TODO Auto-generated method stub } }
答案 0 :(得分:1)
您需要将侦听器添加到GlobalScreen对象并使程序保持运行。