简体   繁体   中英

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.

I'm not sure it's what you want, but you might have a look at this game's key-event editor, pictured in a screenshot and implemented in org.gcs.robot.RCKeys .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM