All global key presses have the same device handle
See original GitHub issueWith 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.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You will have to initialize the GlobalKeyBoardHook with the parameter true
new GlobalKeyboardHook(true)
, to enable the new “raw input” mode. Iffalse
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.
Well at least I wanted to highlight the severity of minor version 3.1 😉