How to get keystrokes with java outside of frames

631 views Asked by At

I know there is a way to get mouse coordinates outside of frames (using MouseInfo). Is there a way to be able to get keyboard input as well? A method that is fired when a key is pressed would be preferred, but if the method has to check for what key is pressed by itself, that also works too. Thanks in advance!

I also am looking for a way to do without installing packages. (so jna wouldn't work)

1

There are 1 answers

0
Max K On

If you are talking about getting keyboard input when the JFrame itself is not selected, due to Java being a virtual machine, it has its limits. Only when a JFrame is selected can you get key strokes. Other languages can achieve this, but unfortunately Java is limited to what is inside the JFrame last time I checked. You could try this: Is there a way to get keyboard events without JFrame?

But if you don't have the frame present I think you might have to involve different languages.