Skip to content

How do I remap the NumLock key in Java Swing?

You may have read my earlier question about remapping my keyboard at a low level in Java and I did find a solution – mostly.

To be honest, I oversimplified the problem I was trying to solve. I not only want to match NumericKeypad 1-3 to 7-9 and vice versa, I want to remap the whole numeric keypad. In particular, I need to remap the NumLock key which is part of that keypad. This seems to be intercepted on a System level and I cannot just map it to emit some character.

What I want is that when running my application, the NumLock key does not toggle the system NumLock setting, but instead emits some other key.

Am I beyond the realm of what is possible in Java here? Or is there some way I can dig down to this low level and accomplish this as well.



The solution I came up with won’t work for everyone, but it’s actually optimal in our use-case:

Use the Windows registry to do the keyboard remapping.

It’s permanent, requires no JNI or device-driver writing and in our case we have no worries about messing up the keyboard for other applications. Very simple.

If you need to do this and can get away with this hack, it’s the cost-effective solution.

User contributions licensed under: CC BY-SA
5 People found this is helpful