2013-03-20 33 views
3

我無法在我的代碼中匹配@的密鑰代碼。我想在keydownhandler中匹配@我已轉移+ 2 = @ = 64如何在Gwt中獲取@的密鑰代碼

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

什麼是'itemBox'? – Apurv 2013-03-20 12:16:13

+0

它是一個文本框 – 2013-03-20 12:27:16

+0

即時通訊也面臨它的問題,在這個即時通訊無法獲得組合鍵的代碼,如shift + 2 = @ = 64 但返回時16,當我們按Shift鍵,然後返回50時2。 – 2013-03-20 12:28:42

回答

2

我得到它感謝名單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

您可以使用keyPressed事件

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

實際上,看起來你**必須**使用'keypress'。在法文鍵盤上,「@」位於AltGr + 0(或Ctrl + Alt + 0),0的「keydown」顯然沒有修飾符(在Chrome中,在Linux上,在http:// unixpapa .com/js/testkey.html) – 2013-03-20 13:33:23

+0

KeyAdapter在GWT中不可用? – SSR 2013-03-20 14:01:33

+0

既不是KeyAdapter也不是addkeyListener它是addkeyboardListener,它也被棄用 – 2013-03-21 10:08:32