tulskiy / jkeymaster

A library for registering global hotkeys in java with JNA. The goal is to support X11-based platforms, Windows and MacOSX
GNU Lesser General Public License v3.0
234 stars 45 forks source link

The "Released" and "Down" seems not working properly #17

Closed flyfy1 closed 10 years ago

flyfy1 commented 10 years ago

Thanks for supplying this library, it looks really nice :)

Here's my working example:

    Provider provider = Provider.getCurrentProvider(false);

    HotKeyListener keyListener = new HotKeyListener() {
        @Override
        public void onHotKey(HotKey key) {
            System.out.println("Hot Key Pressed: " + key);
        }
    };

    provider.register(KeyStroke.getKeyStroke('M',KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK),keyListener);
    provider.register(KeyStroke.getKeyStroke('A',KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK,true),keyListener);
    provider.register(KeyStroke.getKeyStroke('M',KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK,true),keyListener);

However, at my last register statement, I got "WARNING: Could not register HotKey: shift ctrl released M. Error code: -9878". Additionally, the release event was populated, when I simply press the key without actually releasing it.

I'm using Java6 on Mac

tulskiy commented 10 years ago

I don't check the key pressed or released property when registering a hotkey. As you can see in CarbonProvider, it explicitly sets kEventHotKeyPressed as parameter. From what I can see, windows and linux providers do not have that option, so I decided to not do it for osx. If you feel in the mood to dust off old Carbon doc files and implement this feature, I'll be happy to accept a pull request :)