很简单我的朋友:
你所要做的就是创造一个
class KeyEventDispatcher并注册到KeyboardFocusManager C.1
然后解析并提取状态和密钥信息,参见:C.2
奇怪的是,你必须通过ThatEvent.getID()获得KEY STATE;
看起来像我的一个小姐。
/// C.1)
KeyDispatcher ThisKeyDispatcher = new KeyDispatcher();
KeyboardFocusManager ThisKbFocusMngr = KeyboardFocusManager
. getCurrentKeyboardFocusManager();
ThisKbFocusMngr . addKeyEventDispatcher(ThisKeyDispatcher);
return ThisKeyDispatcher;
///
C.2
public static class KeyDispatcher implements KeyEventDispatcher {
public boolean dispatchKeyEvent(final KeyEvent ThatEvent) {
KeyboardFocusManager ThisKbFocusMngr = null;
Component ThisComponent = null;
Container ThisRoot = null;
Window ThisWindow = null;
int ThisKeyStateEvent = 0;
try {
ThisKbFocusMngr = KeyboardFocusManager . getCurrentKeyboardFocusManager();
ThisComponent = ThisKbFocusMngr . getFocusOwner();
ThisRoot = ThisKbFocusMngr . getCurrentFocusCycleRoot();
ThisWindow = ThisKbFocusMngr . getActiveWindow();
ThisKeyStateEvent = ThatEvent.getID(); // i.e. KeyEvent.KEY_RELEASED
if(false == ThatEvent.isConsumed()) {
boolean RetBool = false;
if((KeyEvent.VK_BACK == ThatEvent.getKeyCode())) {
RetBool = true;
} else {
RetBool = m_CallSomeoneEvent(ThatEvent);
}
if(RetBool) {
ThatEvent.consume();
return true;
}
}
}
catch( Throwable e ) {
LogThis(". ", e);
}
return false;
}
}