3

我无法在我的代码中匹配 @ 的关键代码。我想在keydownhandler中匹配@。我采取了 shift + 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");
            }
        }
    });
4

2 回答 2

2

我明白了,thanx 2 all

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);
            }
        }
    });
于 2013-03-23T12:14:39.653 回答
1

您可以使用keyPressed事件

itemBox.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent event) {
                if (event.getKeyChar() == '@' )
                            {}
            }
        });
于 2013-03-20T12:30:32.683 回答