如何在Java Swing中重新映射NumLock键? [英] How do I remap the NumLock key in Java Swing?

查看:98
本文介绍了如何在Java Swing中重新映射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.

说实话,我简化了我要解决的问题.我不仅要将NumericKeypad 1-3匹配到7-9,反之亦然,我还想重新映射整个数字小键盘.特别是,我需要重新映射作为该键盘一部分的NumLock键.这似乎是在系统级别上被拦截的,我不能仅仅将其映射为发出一些字符.

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.

我想要的是,在运行应用程序时,NumLock键不会切换系统NumLock设置,而是发出一些其他键.

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.

我超出了Java可能实现的范围吗?还是有某种方法可以使我深入到这个低水平并完成此工作.

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:

使用Windows注册表进行键盘重新映射.

Use the Windows registry to do the keyboard remapping.

它是永久性的,不需要编写JNI或设备驱动程序,并且在我们的情况下,我们无需担心会为其他应用程序弄乱键盘.很简单.

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.

这篇关于如何在Java Swing中重新映射NumLock键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆