Out of curiosity, I thought I'd try a solution using Roycefers
jNativeHook library. There are obvious potential issues using this kind of library, mainly it is important to make sure that you stop the native hook when the app is closed. Due to it's nature, it is not simple to work with, but it can be very effective and I have an app that relies on it which I use daily and have done for the last 3 or 4 years with no issues.
Please read carefully Roycefer's comments in the library post.
I have tested this on java 8 and 11, and have added the code to capture mouse press which you may want and requires the Threading library and therefore may not run properly in debug mode unless you compile it to a library. If you don't need it I suggest that you remove it.
It's not going to be perfect as it stands but should give you a start. I hope this helps.