View RSS Feed

DuvanSlabbert

Adding "Global" KeyListener

Rate this Entry
by , 10-17-2011 at 06:00 PM (5125 Views)
Want to add a so called "Global" Keylistener to your Java application even if it is a JWindow or JFrame without having focus on it. Just download the file in the link and extract, add the jhook.jar file to your project library and use this demo code to get the keys pressed.

Java Code:
Keyboard kb=new Keyboard();
        kb.addListener(new KeyboardListener() {
            public void keyPressed(boolean keydown, int vk){
                System.out.println(vk);
            }
        });
JHook.zip

Submit "Adding "Global" KeyListener" to Facebook Submit "Adding "Global" KeyListener" to Digg Submit "Adding "Global" KeyListener" to del.icio.us Submit "Adding "Global" KeyListener" to StumbleUpon Submit "Adding "Global" KeyListener" to Google

Updated 10-19-2011 at 08:33 AM by DuvanSlabbert

Categories
AWT and Swing

Comments

  1. JavaForums's Avatar
    • |
    • permalink
    Hi Duvan,

    Thanks for sharing.

    I have a question. Does this work for only windows?

    By the way, why didn't you attach the code to the post? Did you observe a limitation?
  2. DuvanSlabbert's Avatar
    • |
    • permalink
    I have searched long and wide to get a cross-platform version for doing this, even tried some funny things of implementing keyListeners to threads... but with no success. Unfortunately this is only for Windows, my search will still go on until I get the so called "Global Keylistener" effect in java which is cross-platform based. The file in a zipped format is just under a Meg in size and was restricted to the maximum of 97.7kb
  3. AlphaSupport's Avatar
    • |
    • permalink
    Hello Duvan,

    We have now raised the filesize limit for ZIP-files to 15Mb.

    Can you please test attaching the file directly to your post now?

    Regards,
    Marco
  4. DuvanSlabbert's Avatar
    • |
    • permalink
    It works without any further problems.
    Thank you so much.
    Updated 10-19-2011 at 08:03 PM by DuvanSlabbert