如何在Gwt中获取@的密钥代码

时间:2013-03-20 11:58:29

标签: java gwt

我无法在我的代码中匹配@的密钥代码。我想在keydownhandler中匹配@。我采取了班次+ 2 = @ = 64

itemBox.addKeyDownHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent event) {
            // TODO Auto-generated method stub
            if ((int)event.getNativeKeyCode() == 64 )
            {
                System.out.println("eggheads");
            }
        }
    });

2 个答案:

答案 0 :(得分:2)

我得到了所有

inputBox.addKeyPressHandler(new KeyPressHandler() {
                public void onKeyPress(KeyPressEvent event) {
            // TODO Auto-generated method stub
            System.out.println(event.getUnicodeCharCode());

            if(event.getUnicodeCharCode() == 64){
            item.add(box);
            }
        }
    });

答案 1 :(得分:1)

您可以使用keyPressed活动

itemBox.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent event) {
                if (event.getKeyChar() == '@' )
                            {}
            }
        });