日期:2014-05-20 浏览次数:20781 次
public focustest() {//构造方法 ............... Toolkit tk = Toolkit.getDefaultToolkit(); tk.addAWTEventListener(new GlobalEventListener(),AWTEvent.KEY_EVENT_MASK); } class GlobalEventListener implements AWTEventListener {//子类 public void eventDispatched(AWTEvent evt) { if (evt instanceof KeyEvent) { KeyEvent kevt = (KeyEvent) evt; if (kevt.getID() == KeyEvent.KEY_PRESSED) { String modifier = KeyEvent.getKeyModifiersText(kevt.getModifiers()); String key = KeyEvent.getKeyText(kevt.getKeyCode()); System.out.println("Modifier:"+modifier+"|Key:"+key); } } } }