How do I remap the NumLock key in Java Swing?

蓝咒 提交于 2019-12-11 07:31:31

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/6366095/how-do-i-remap-the-numlock-key-in-java-swing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!