ilbinek ilbinek - 3 years ago 122
Java Question

Java read input directly from keyboard

I am trying to make a program, that listens to keyboard input all the time. When specific key is pressed, something will happen. I will use daemon thread to do the reading. The problem I got is how to get input directly from keyboard. User won't type into the console (I am using JavaFX, so no console at all). The cursor is focused on different app, but the daemon thread is still getting it. Don't worry, I am not planning to create a keylogger!

Thanks for all your advices.

Answer Source

Solution depends on what actual platform/OS is targeted. Some even does not have keyboard. Thus it would be better to use different language, which is more close to operating system and OS API (for example C++). Also you may try to use Java with C++ by utilizing JNI.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download