import javafx.scene.input.KeyCode; //導入方法依賴的package包/類
@SuppressWarnings(“deprecation”) private void dispatchKeyEvent(final Node node, JavaAgentKeys keyToPress,
EventType eventType, char c) {
ensureVisible(node);
if (keyToPress == null) {
KeyboardMap kbMap = new KeyboardMap(c);
KeyCode keyCode = KeyCode.getKeyCode((kbMap.getChar() + “”).toUpperCase());
if (eventType.getName().equals(“KEY_TYPED”)) {
keyCode = KeyCode.UNDEFINED;
}
int modifiersEx = deviceState.getModifierEx();
char char1 = kbMap.getChar();
if (modifiersEx == 0) {
modifiersEx = kbMap.getModifiersEx();
dispatchEvent(new KeyEvent(eventType, char1 + “”, char1 + “”, keyCode, deviceState.isShiftPressed(),
deviceState.isCtrlPressed(), deviceState.isAltPressed(), deviceState.isMetaPressed()), node);
} else {
dispatchEvent(new KeyEvent(eventType, char1 + “”, char1 + “”, keyCode, deviceState.isShiftPressed(),
deviceState.isCtrlPressed(), deviceState.isAltPressed(), deviceState.isMetaPressed()), node);
}
return;
}
final KeysMap keysMap = KeysMap.findMap(keyToPress);
if (keysMap == null) {
return;
}
deviceState.toggleKeyState(keyToPress);
dispatchEvent(new KeyEvent(eventType, KeyCode.UNDEFINED.impl_getChar(), KeyCode.UNDEFINED.impl_getChar(), keysMap.getCode(),
deviceState.isShiftPressed(), deviceState.isCtrlPressed(), deviceState.isAltPressed(), deviceState.isMetaPressed()),
node);
}