mac 中判断command键是否被按下 博客分类: macjava swing command按下commandcmd键
程序员文章站
2024-03-02 09:18:40
...
mac 中判断command键是否被按下
使用KeyEvent.isMetaDown()
实例:
/*** * 增加全局快捷键Shift+Tab<br> * Ctrl+Shift+X */ private void addGlobalKey(){ Toolkit toolkit = Toolkit.getDefaultToolkit(); // 注册应用程序全局键盘事件, 所有的键盘事件都会被此事件监听器处理. toolkit.addAWTEventListener( new java.awt.event.AWTEventListener() { public void eventDispatched(AWTEvent event) { if (event.getClass() == KeyEvent.class) { KeyEvent kE = ((KeyEvent) event); // 处理按键事件 Shift+Tab if ((kE.getKeyCode() == KeyEvent.VK_TAB)//TODO 注意:Ctrl+Tab 是系统的快捷键,容易和程序混淆 && (((InputEvent) event) .isShiftDown())&& kE.getID() == KeyEvent.KEY_PRESSED) { int lastIndex=getLastIndex(); if(lastIndex<0){ return; } // indexList.add(tabbedPane.getSelectedIndex()); tabbedPane_2.setSelectedIndex(lastIndex); } else if ((kE.getKeyCode() == KeyEvent.VK_X) && (((InputEvent) event)//发送请求 .isShiftDown()) && (((InputEvent) event) .isAltDown()) && kE.getID() == KeyEvent.KEY_PRESSED) {//Alt+Shift+X AutoTestPanel.this.currentRequestPanel.requestAction(null, true); } else if ((kE.getKeyCode() == KeyEvent.VK_M) && (!((InputEvent) event)//发送请求 .isShiftDown()) && (((InputEvent) event) .isControlDown()) && kE.getID() == KeyEvent.KEY_PRESSED) {//Ctrl+Shift+M DialogUtil.showMaximizeDialog(getCurrentRequestPanel().getRespTextArea_9()); } else if ((kE.getKeyCode() == KeyEvent.VK_H) && (!((InputEvent) event)//发送请求 .isShiftDown()) && (((InputEvent) event) .isControlDown()) && kE.getID() == KeyEvent.KEY_PRESSED) {//Ctrl+Shift+M TableUtil.showHelpDialog(); } else if (kE.getKeyCode() == KeyEvent.VK_K/*Ctrl +K*/ && (kE.isControlDown()||kE.isMetaDown()) && kE.getID() == KeyEvent.KEY_PRESSED) { searchTextField.requestFocus(); searchTextField.selectAll(); } } } }, java.awt.AWTEvent.KEY_EVENT_MASK); }
上一篇: python urllib爬取百度云连接的实例代码
下一篇: Python处理Excel文件实例代码