• Log in or sign up for an account here: https://www.sythe.org/login

Java global hotkeys without use of JNI?

Blupig

BEEF TOILET

$5 USD Donor
Joined
Nov 23, 2006
Sythe Gold
1,609
Messages
7,145
Age
33
Location
Canada
Valentine's Singing Competition Winner
Sythe Awards 2015 Winner
Sythe Awards 2016 Winner
Sythe Awards 2020 Winner
Member of the Month Winner
MushyMuncher
Gohan has AIDS
Extreme Homosex
World War 3
I'm LAAAAAAAME
Discord Verified
Off Topic Participant
Hey, I'm looking for a way to set some global hotkeys in Java without writing code native to each OS. This application is meant to be cross-platform in its purest sense.

The program will be minimized and will be performing actions with the mouse and keyboard. Obviously, the user can't open the program again to stop it, so a global hotkey (shift+F11 or something) is needed.

Anyone know where I can start looking?
 
Supporting Business
Discord Voice
Poképedia
Who did this to my freakin' car!
Dat Boi
Dolan Duck
Dolan Trump
I'm LAAAAAAAME
Live Free or Die
Mew
Mewtwo
Poké Prizebox
Rust Player
Sythe Awards 2016 Winner
Sythe Awards 2017 Winner
Sythe Awards 2019 Winner
Tier 3 Prizebox
Toast Wallet User
Hey, I'm looking for a way to set some global hotkeys in Java without writing code native to each OS. This application is meant to be cross-platform in its purest sense.

The program will be minimized and will be performing actions with the mouse and keyboard. Obviously, the user can't open the program again to stop it, so a global hotkey (shift+F11 or something) is needed.

Anyone know where I can start looking?
The API for low level keyboard hooks are different for each OS and I believe global hooks break javas security model. You'll have to provide native hooks for each OS you want to support
 
  • Like
Reactions: Eru
Valentine's Singing Competition Winner
Sythe Awards 2015 Winner
Sythe Awards 2016 Winner
Sythe Awards 2020 Winner
Member of the Month Winner
MushyMuncher
Gohan has AIDS
Extreme Homosex
World War 3
I'm LAAAAAAAME
Discord Verified
Off Topic Participant
The API for low level keyboard hooks are different for each OS and I believe global hooks break javas security model. You'll have to provide native hooks for each OS you want to support

Found a good library that does it for me, @Jiwi linked it to me but deleted his reply for some reason.
 
Last edited:
Two Factor Authentication User
Yeah I didn't see that the library I linked already took care of the cross-platform recoding issues Blu was worried about with JNI. Figured it was useless to link at first, but it creates separate code for each platform so that's nice I suppose

jnativehook/src at master · kwhat/jnativehook · GitHub

lol! said:
JNativeHook leverages platform-dependent native code through Java's native interface to create low-level system-wide hooks and deliver those events to your application.
 
Last edited:
You'll have to use JNI.

If we use Windows has an example, because when you click a keyboard character on Windows,
Windows dispatches a message to the message queue.

You can hook these natively using WinAPI but the JVM has no built in facilities for doing this as it differs per platform greatly.
The only thing you can hook in Java for keyboard shit is focused Java GUI AWT components where the event queue has to process all of the characters.
The JVM isn't globally caring for whatever messages/events Windows itself dispatches.

Hope this was useful,
If you've got any questions feel free to PM me.
 
Runescape Gamblingrunescape gambling
Back
Top