Java 键盘键码列表 [英] Java Keyboard Keycodes list

查看:33
本文介绍了Java 键盘键码列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以为我提供键盘上用于 Java 中 KeyEvent 类的各个键的键代码整数列表吗?

Can anybody provide me with the Key Code integer list for individual keys used on the Keyboard for the KeyEvent class in java?

我想创建一个包含所有键盘键的下拉列表供用户选择.我需要特定于键盘的列表.VK 常量在这种情况下没有帮助,因为我需要键盘上使用的键的列表".这里的这篇文章没有用,因为它用于 Javascript,与 javadoc.还有 javadoc 都是按字母顺序排列的,所以很难找到那边的键盘键.我尝试在谷歌上搜索源代码,但没有任何有趣的东西出现在 Javascript 上.我应该自己一个一个编译它们还是有更简单的方法?

I want to create a dropdown list of all the keyboard keys for the user to select. I need the list specific to Keyboard. The VK constants does not help in this case because I need a 'list' of Keys used on the Keyboard. This post here didn't come of use because it's for Javascript and the codes aren't the same for all keys comparing with the javadoc. Also the KeyCode values used in javadoc are all arranged in Alphabetical Order, so it's hard to find the Keyboard keys over there. I tried googling for sources but nothing interesting came up just the Javascript one. Should I just compile them one by one myself or is there an easier way?

我知道 VK.我需要使用 KeyEvent.getKeyText 函数将每个键盘键存储在下拉菜单中.所以我需要这份清单.这就是为什么我问我是否需要自己编译它们.我应该早点提到这一点.为每个键都这样做是浪费时间.

I know about VK. I need to use KeyEvent.getKeyText function to store each of the keyboard keys in a dropdown menu. So i need the list. That's why I asked should I need to compile them myself. I should have mentioned that earlier. It would be a waste of time doing that for each key.

推荐答案

KeyEvent 类具有具有这些值的静态字段.

KeyEvent class has static fields with these values.

例如,KeyEvent.VK_A 代表A"键.

要获取字段名称,您可以使用反射:

To get the fields names you can use reflection:

Field[] fields = java.awt.event.KeyEvent.class.getDeclaredFields();
for (Field f : fields) {
    if (Modifier.isStatic(f.getModifiers())) {
        System.out.println(f.getName());
    } 
}

这篇关于Java 键盘键码列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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