通用密钥代码(Java) [英] Universal Key Code (Java)

查看:132
本文介绍了通用密钥代码(Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在对一个侦听器进行编程,该侦听器必须根据用户所按下的键以某种方式起作用.

Hi I'm programming a listener that based on the key pressed by the user, must act in a certain manner.

我需要确定用户是否按下 I 键或 M 键.其实我是这样的:

I need to be able to determine if a user press the I key or M key. Actually I'm doing it like:

// If pressed the 'i' key
if ( evt.getKeyCode() == 73) {
    //
}
...

我在这里看到,示例小程序确定 I 密钥被识别为73码.

I look out here and with the sample applet determine that the I key is recognized as a 73 code.

那行得通.

但是我正在Mac OS X上工作,我不知道是否曾经尝试在另一个OS或JVM上运行此应用程序,

But I'm working at Mac OS X, and I don't know if once I try to run this app on another OS or just JVM, It won't work.

73是通用密钥代码吗?是否有某种方法可以对此编程,以便它可以运行并确定在Windows上按下的键.

Is the 73 a universal key code? Is there a certain way to program this so it can run and determine the key pressed, on windows.

谢谢!

推荐答案

只需补充Paul Brinkley的 answer .

Just complementing Paul Brinkley's answer.

73是通用密码吗?

Is the 73 a universal key code?

是的,它是大写字母"I"的 ASCII 代码这种情况.请参见 KeyEvent.VK_A

Yes, it is the ASCII code of the upper case letter, 'I' in that case. See the javadoc for KeyEvent.VK_A

尽管有巧合,但最好不要做getKeyCode() == 'A'之类的事情-在将来的实现中它可能会失败.

despite this coincidence, it's better not to do something like getKeyCode() == 'A' - it may fail in future implementations.

这篇关于通用密钥代码(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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