如何在java中获取键盘扫描代码? [英] How can I get the keyboard scan code in java?

查看:607
本文介绍了如何在java中获取键盘扫描代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个应用程序,其中键绑定特定于键盘上键的位置,而不是它们映射到的字符。例如,美国键盘上t和u之间的键应该执行特定的功能,无论它是在美国还是Z,就像它在德国一样。



我认为这样做的方法是将键盘给出的实际扫描码提供给OS来表示按下的键。我怎么能在java中做到这一点?



或者还有其他方法可以实现相同的功能吗?

MadProgrammer 说:你必须使用JNA或JNI。您还可以查看这些项目:






JIntellitype是一个Java API,用于与Microsoft Intellitype
命令交互以及在Java
应用程序中注册Global Hotkeys。 API是一个Java JNI库,它使用C ++ DLL与Windows进行所有通信


有类似的项目 Linux Mac OS X









JNativeHook是一个提供全局键盘和鼠标
监听器的库Java的。这将允许您监听全局快捷方式
或鼠标运动,否则使用纯Java将无法实现。为了
完成此任务,JNativeHook通过Java的本机接口利用平台相关的本机
代码创建低级系统范围的
挂钩,并将这些事件传递给您的应用程序。









仅限Windows,能够赢得Win 7/8(32位和64位)







I would like to write an application where the keybindings are specific to the location of the key on the keyboard, not the character they are mapped to. For example, the key that is between t and u on a US keyboard should perform a specific function, regardless of whether it is Y as it is in the US or Z as it is in Germany.

I think the way to do this would be to get the actual scan code given by the keyboard to the OS to represent the key that was pressed. How can I do this in java?

Or is there another way to achieve the same functionality?

解决方案

As MadProgrammer said: You have to use JNA or JNI. You can also have a look at those projects:

JIntellitype is a Java API for interacting with Microsoft Intellitype commands as well as registering for Global Hotkeys in your Java application. The API is a Java JNI library that uses a C++ DLL to do all the communication with Windows.

There are similar projects Linux and Mac OS X.


JNativeHook is a library to provide global keyboard and mouse listeners for Java. This will allow you to listen for global shortcuts or mouse motion that would otherwise be impossible using pure Java. To accomplish this task, JNativeHook leverages platform dependent native code through Java's native interface to create low level system wide hooks and deliver those events to your application.


Windows only, capable of Win 7 / 8 (32 and 64 bit)


这篇关于如何在java中获取键盘扫描代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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