方括号的键码是什么 [英] What's the keycode of the square brackets

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

问题描述

我正在尝试使用Java中的Robot类并键入一些文本.不幸的是,我在查找方括号,此符号|和此符号`的键代码时遇到问题.我在KeyEvent常量中找不到它们.我要使用它们,因为我键入的文本是西里尔字母,并且这些符号表示字母中的字符.预先感谢.

I'm trying to use the Robot class in Java and type some text. Unfortunately I'm having problems finding the key codes of the square brackets, this symbol | and this symbol `. I can't find them in the KeyEvent constants. I want to use them, because the text i'm typing is in cyrillic and these symbols represent characters in the alphabet. Thanks in advance.

推荐答案

它位于 KeyEvent.VK_OPEN_BRACKET

KeyEvent.VK_CLOSE_BRACKET

修改

KeyEvent JavaDoc

此低级事件由组件对象(例如 文本字段),当按下,释放或键入一个键时.

This low-level event is generated by a component object (such as a text field) when a key is pressed, released, or typed.

因此,在美国101键键盘上,尽管将具有`和将产生相同的键码. > SHIFT 修改器.另请注意,KeyEvent.VK_BACK_SLASH也会捕获 | (管道)按键.

So on a US 101-key keyboard, the ` and ~ will produce the same keycode, although ~ will have a SHIFT modifier. Also notice that KeyEvent.VK_BACK_SLASH traps the | (pipe) keystroke too.

尝试将以下示例KeyAdapter添加到您的项目中,以查看实际效果.

Try adding the following sample KeyAdapter to your project to see this in action.

new KeyAdapter()
{
    public void keyPressed(final KeyEvent e)
    {
        if (e.getKeyCode() == KeyEvent.VK_BACK_QUOTE)
        {
            e.toString();
        }
        if (e.getKeyCode() == KeyEvent.VK_BACK_SLASH)
        {
            e.toString();
        }
        if (e.getKeyCode() == KeyEvent.VK_OPEN_BRACKET)
        {
            e.toString();
        }
    }
}

这篇关于方括号的键码是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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