java 扫描键盘,如何在java中获取键盘扫描代码?

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:

(Windows only)

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.

(Windows, Linux and Mac OS?)

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值