2010-08-11 89 views
2

我试图绑定Windows使用Java的密钥,我失败了。 我可以绑定AltCtrl键与别的东西。Java:绑定Windows密钥

但是,如果我想使用Windows密钥,我无法得到它。

可能吗?

回答

3

它为我工作我用KeyEvent类的以下常量。

/** 
* Constant for the Microsoft Windows "Windows" key. 
* It is used for both the left and right version of the key. 
* @see #getKeyLocation() 
* @since 1.5 
*/ 
public static final int VK_WINDOWS     = 0x020C; 

我实现我的KeyListener方法在下面的方式和它的工作(我使用Ubuntu 10):

// Invoked when a key has been pressed. 
    public void keyPressed(KeyEvent e) { 
     // Returns the integer code for the key on the keyboard and if 
     // keyCode is equal to VK_WINDOWS)... 
     if (e.getKeyCode() == KeyEvent.VK_WINDOWS) { 
      // ...call the doIT method. 
      doIT(); 
     } 
    } 
1

在Linux上,Windows密钥通常映射到元密钥,因此请尝试Event.META_MASK

+0

Event.META_MASK并没有为我工作在Ubuntu 10 – YoK 2010-08-11 08:29:32

+0

Ubuntu的映射到“超”。 Opensuse将其映射到“Meta”。你可以使用xmodmap来改变它。 – 2010-08-11 10:02:44