如何在 Java Swing 中重新映射 NumLock 键?
您可能已经阅读过我的之前的问题,关于重新映射我的Java 中的低级别键盘,我确实找到了解决方案 - 主要是。
老实说,我把我想要解决的问题过于简单化了。我不仅想将数字键盘 1-3 匹配到 7-9,反之亦然,我想重新映射整个数字键盘。特别是,我需要重新映射 NumLock 键,它是该键盘的一部分。这似乎在系统级别被拦截,我不能只是将其映射以发出一些字符。
我想要的是,当运行我的应用程序时,NumLock 键不会切换系统 NumLock 设置,而是发出一些其他键。
我是否超出了 Java 所能实现的范围?或者有什么方法可以让我深入到这个低水平并完成这个任务。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我提出的解决方案并不适合所有人,但它实际上在我们的用例中是最佳的:
使用 Windows 注册表进行键盘重新映射。
它是永久性的,不需要编写 JNI 或设备驱动程序,在我们的例子中,我们不用担心会弄乱其他应用程序的键盘。很简单。
如果您需要这样做并且可以摆脱这种黑客攻击,那么这是一种经济高效的解决方案。
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.
我不确定这是否是您想要的,但您可能会看看这个游戏的键-事件编辑器,如屏幕截图所示,如下所示并在
org.gcs.robot .RCKeys
。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, shown below and implemented in
org.gcs.robot.RCKeys
.