question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

All global key presses have the same device handle

See original GitHub issue

With the code

GlobalKeyboardHook globalKeyboardHook = new GlobalKeyboardHook();

        globalKeyboardHook.addKeyListener(new GlobalKeyAdapter(){
            @Override
            public void keyPressed(GlobalKeyEvent event) {
                System.out.println(event.getVirtualKeyCode());
                System.out.println("Keyboard: " + event.getDeviceHandle());
            }
        });

It gives me a device handle of 0 even though I have 2 Logitech keyboards plugged in (one wireless, one wired). I restarted the application to try again and it still persisted. image image image

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kristiancommented, Jun 11, 2017

You will have to initialize the GlobalKeyBoardHook with the parameter true new GlobalKeyboardHook(true), to enable the new “raw input” mode. If false is passed, you are still using the old keyboard hook (for legacy compliance reasons). As soon as you “switch on” raw mode, you should get the device ID.

Thanks for noticing the typo. I’ll fix it and re-upload a 3.1 build. Thanks.

0reactions
kristiancommented, Jun 11, 2017

Well at least I wanted to highlight the severity of minor version 3.1 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

swing - Handle keypress in java (globally) - Stack Overflow
Yes, the solution will be related to key bindings. But what if he has a JTextField that has focus and you want to...
Read more >
What Happens Inside Your Computer When a Key is Pressed?
Each key on the keyboard has an associated number, called a scan code. ... react immediately to key presses, so it has to...
Read more >
Element: keypress event - Web APIs | MDN
The keypress event is fired when a key that produces a character value is pressed down.
Read more >
Keyboard Input (Get Started with Win32 and C++)
Virtual-key codes are device-independent. Pressing the A key on any keyboard generates the same virtual-key code. In general, virtual-key codes ...
Read more >
Keyboard: keydown and keyup - The Modern JavaScript Tutorial
Before we get to keyboard, please note that on modern devices there ... For instance, the same key Z can be pressed with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found