Using Java, How to detect keypresses without using GUI components?

Using Java, is it possible to detect user actions, such as key-presses, mouse-button-presses, and/or mouse’s screen location, without the use of GUI elements?

If it is, how could I implement it?

Otherwise, what are the alternatives?

The only StackOverflow source i found on this matter is this question, which is unanswered.

And the only sources I found outside StackOverflow on this matter point to an “Invisible GUI” solution, wish is something i really want to avoid.