E
E
empr2016-12-03 23:33:44
Java
empr, 2016-12-03 23:33:44

How to distinguish pressing the "left" key from Num 4 with Num Lock disabled?

Greetings! I use jnativehook, but it's probably not the tool.
How can I distinguish between pressing Num 4 and pressing the left button with Num Lock off? Here's what I write about it in the log:


Raw code: 37
Key code: 57419
Key location: 1
Modifiers: 0
Raw code: 37
Key code: 57419
Key location: 1
Modifiers: 0

At the same time, the PassMark KeyboardTest program manages to issue BIOS Key Code 75 for this key, regardless of the state of NumLock. Or does it just check if NumLock is enabled? But this option is the least desirable for me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
exenza, 2016-12-04
@empr

In my case, jnativehook returns the same keyCode, but the keyRawCode is different (version 2.0.2):
Example:

import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;

public class KeyEventDemo implements NativeKeyListener {

    public static void main(String[] args) {
        try {
            GlobalScreen.registerNativeHook();
        }
        catch (NativeHookException ex) {
            System.err.println(ex.getMessage());
            System.exit(1);
        }

        GlobalScreen.addNativeKeyListener(new KeyEventDemo());
    }

    @Override
    public void nativeKeyPressed(final NativeKeyEvent nativeKeyEvent) {
        System.out.println("Key code: " + nativeKeyEvent.getKeyCode()
                + ", raw code: " + nativeKeyEvent.getRawCode());
    }

    @Override
    public void nativeKeyReleased(final NativeKeyEvent nativeKeyEvent) {}

    @Override
    public void nativeKeyTyped(final NativeKeyEvent nativeKeyEvent) {}
}

@param rawCode the hardware code associated with the native key in this event.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question