Java global hotkeys without use of JNI?

Discussion in 'Programming General' started by Blupig, Feb 9, 2017.

Java global hotkeys without use of JNI?
  1. Unread #1 - Feb 9, 2017 at 2:02 AM
  2. Blupig
    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant

    Blupig BEEF TOILET
    $5 USD Donor

    Java global hotkeys without use of JNI?

    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?
     
  3. Unread #2 - Feb 10, 2017 at 2:55 PM
  4. Sythe
    Joined:
    Apr 21, 2005
    Posts:
    8,071
    Referrals:
    465
    Sythe Gold:
    5,271
    Discord Unique ID:
    742989175824842802
    Discord Username:
    Sythe
    Dolan Duck Dolan Trump Supporting Business ???
    Poképedia
    Clefairy Jigglypuff
    Who did this to my freakin' car!
    Hell yeah boooi
    Tier 3 Prizebox Toast Wallet User
    I'm LAAAAAAAME Rust Player Mewtwo Mew Live Free or Die Poké Prizebox (42) Dat Boi

    Sythe Join our discord

    test

    Administrator Village Drunk

    Java global hotkeys without use of JNI?

    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
     
    ^ Eru likes this.
  5. Unread #3 - Feb 10, 2017 at 4:26 PM
  6. Blupig
    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant

    Blupig BEEF TOILET
    $5 USD Donor

    Java global hotkeys without use of JNI?

    Found a good library that does it for me, @Jiwi linked it to me but deleted his reply for some reason.
     
    Last edited: Feb 10, 2017
  7. Unread #4 - Feb 10, 2017 at 4:27 PM
  8. Sythe
    Joined:
    Apr 21, 2005
    Posts:
    8,071
    Referrals:
    465
    Sythe Gold:
    5,271
    Discord Unique ID:
    742989175824842802
    Discord Username:
    Sythe
    Dolan Duck Dolan Trump Supporting Business ???
    Poképedia
    Clefairy Jigglypuff
    Who did this to my freakin' car!
    Hell yeah boooi
    Tier 3 Prizebox Toast Wallet User
    I'm LAAAAAAAME Rust Player Mewtwo Mew Live Free or Die Poké Prizebox (42) Dat Boi

    Sythe Join our discord

    test

    Administrator Village Drunk

    Java global hotkeys without use of JNI?

    Lol k
     
  9. Unread #5 - Feb 10, 2017 at 7:55 PM
  10. Jiwi
    Joined:
    Sep 26, 2011
    Posts:
    2,325
    Referrals:
    2
    Sythe Gold:
    278
    Discord Unique ID:
    271553932852068353
    Two Factor Authentication User

    Jiwi Grand Master
    Competition Winner

    Java global hotkeys without use of JNI?

    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

     
    Last edited: Feb 10, 2017
  11. Unread #6 - Oct 4, 2017 at 2:02 PM
  12. 146918496
    Joined:
    Oct 1, 2017
    Posts:
    29
    Referrals:
    1
    Sythe Gold:
    30

    146918496 Member
    Banned

    Java global hotkeys without use of JNI?

    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.
     
< Circular 4-bit rotations (for fun) | Youtube Viewbot - Help >

Users viewing this thread
1 guest


 
 
Adblock breaks this site