为了账号安全,请及时绑定邮箱和手机立即绑定

知道是否按下 Java 中的热键或快捷键

知道是否按下 Java 中的热键或快捷键

莫回无 2021-10-28 09:43:24
如何检测何时按下快捷键Ctrl+ A、Ctrl+C或Ctrl+V并继续执行它们的快捷键功能。他们要求我在java的这个功能下做,编辑可能只听所说的快捷方式。这是可行的吗?TCombo combo = new TCombo();JTextComponent editor = (JTextComponent) combo.getEditor().getEditorComponent();editor.addKeyListener(new KeyAdapter() {public void keyPressed(KeyEvent e) {    String keyChar = String.valueOf(e.getKeyChar());    int keyCode = e.getKeyCode();    //If Ctrl + A    //do the normal function of select all    //If Ctrl + C    //do the normal function of copy    //If Ctrl + V    //do the normal function of paste    }});
查看完整描述

1 回答

?
炎炎设计

TA贡献1808条经验 获得超4个赞

您应该使用 getModifiers 方法。


if ((e.getKeyCode() == KeyEvent.VK_C) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { 

//Your code here }

请注意,使用 & 运算符是因为它是一个位比较操作。


查看完整回答
反对 回复 2021-10-28
  • 1 回答
  • 0 关注
  • 167 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信