ctrl 的键码
对于 Jtree 中的多重选择,我在其中使用多重选择模式。它可以工作。但是我想知道何时在这棵树中准确地进行多重选择来执行此操作,我编写了一个非常简单的实现 KeyListener 的 keycontroller 类,但是我想检查 CTRL 是否被按下,所以我正在使用此代码,但它似乎不起作用:
kc.getKeyCode() == KeyEvent.CTRL_DOWN_MASK ;
ctrl 的 keyCode 是什么?或者我做错了什么?
For multiple selection in a Jtree,I am using multiple selection mode in it.It works.But I want to know when i am making multiple selection exactly in this tree to do this i wrote a very simple keycontroller class that implements KeyListener, but i wanna check whether CTRL is pressed or not to do so i am using this code but it seems to be not working :
kc.getKeyCode() == KeyEvent.CTRL_DOWN_MASK ;
what is the keyCode for ctrl ? Or am i doing something wrong ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于 CTRL 是一个键掩码,因此 CTRL 键没有单独的字符。
但是,根据 KeyEvent 文档中,按下或释放按键时总会发送一个有效的按键代码。在这种情况下,它应该是
KeyEvent.CHAR_UNDEFINED
和getModifiersEx()
应该为 CTRL 键返回 true。请注意,要使其工作,您必须注册 KeyListener (专门处理 keyPressed() 和 keyReleased())。As CTRL is a key mask, there is no character for the CTRL key alone.
However, according to KeyEvent documentation, there is always a vaild key code that is sent when either a key is pressed or released. in that case, it should be
KeyEvent.CHAR_UNDEFINED
andgetModifiersEx()
should return true for the CTRL key. Notice that, for it to work, you have to register a KeyListener (specially handle for both keyPressed() and keyReleased()).Ctrl 的按键代码是
KeyCode.VK_CONTROL
。为了确定Ctrl是否被按住,您可以这样做:这是使用
java.awt.event.ActionEvent
而不是java.awt.event。按键事件
。因此,ActionEvent
中 Ctrl 的代码是CTRL_MASK
。希望这有帮助。
The key code for Ctrl is
KeyCode.VK_CONTROL
. In order to find if Ctrl is held you can do this:Which is using the
java.awt.event.ActionEvent
instead of thejava.awt.event.KeyEvent
. So the code for Ctrl inActionEvent
isCTRL_MASK
.Hope this helps.