diff --git a/platform/platform-impl/src/com/intellij/ide/CharToVKeyMap.java b/platform/platform-impl/src/com/intellij/ide/CharToVKeyMap.java index 3d15ec4ca98f..92e85cab47d0 100644 --- a/platform/platform-impl/src/com/intellij/ide/CharToVKeyMap.java +++ b/platform/platform-impl/src/com/intellij/ide/CharToVKeyMap.java @@ -29,7 +29,7 @@ class CharToVKeyMap { new HashMap(); public static Integer get (Character ch) { - return charToVKeyMap.get(ch); + return charToVKeyMap.containsKey(ch) ? charToVKeyMap.get(ch) : KeyEvent.VK_UNDEFINED; } static { diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index ce09b77acbe0..9b4dfaa3e9b2 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -439,83 +439,49 @@ public class IdeEventQueue extends EventQueue { // Try to get it from editor Component sourceComponent = WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow(); - if (ke.getID() == KeyEvent.KEY_PRESSED) { - switch (ke.getKeyCode()) { - case KeyEvent.VK_CONTROL: - if ((ke.getModifiersEx() & (InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)) != (InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)) { - ctrlIsPressedCount++; - } - break; - case KeyEvent.VK_ALT: - if (ke.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT) { - if ((ke.getModifiersEx() & (InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)) != (InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)) { - leftAltIsPressed = true; - } - } - break; - } - } - else if (ke.getID() == KeyEvent.KEY_RELEASED) { - switch (ke.getKeyCode()) { - case KeyEvent.VK_CONTROL: - ctrlIsPressedCount = 0; - break; - case KeyEvent.VK_ALT: - if (ke.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT) { - leftAltIsPressed = false; - } - break; - } + switch (ke.getID()) { + case KeyEvent.KEY_PRESSED: + break; + case KeyEvent.KEY_RELEASED: + break; } - if (!leftAltIsPressed && KeyboardSettingsExternalizable.getInstance().isUkrainianKeyboard(sourceComponent)) { - if ('ґ' == ke.getKeyChar() || ke.getKeyCode() == KeyEvent.VK_U) { - ke = new KeyEvent(ke.getComponent(), ke.getID(), ke.getWhen(), 0, - KeyEvent.VK_UNDEFINED, 'ґ', ke.getKeyLocation()); - ke.setKeyCode(KeyEvent.VK_U); - ke.setKeyChar('ґ'); - return ke; - } - } + //if (!leftAltIsPressed && KeyboardSettingsExternalizable.getInstance().isUkrainianKeyboard(sourceComponent)) { + // if ('ґ' == ke.getKeyChar() || ke.getKeyCode() == KeyEvent.VK_U) { + // ke = new KeyEvent(ke.getComponent(), ke.getID(), ke.getWhen(), 0, + // KeyEvent.VK_UNDEFINED, 'ґ', ke.getKeyLocation()); + // ke.setKeyCode(KeyEvent.VK_U); + // ke.setKeyChar('ґ'); + // return ke; + // } + //} + + // NB: Standard keyboard layout is an English keyboard layout. If such + // layout is active every KeyEvent that is received has + // a @{code KeyEvent.getKeyCode} key code corresponding to + // the @{code KeyEvent.getKeyChar} key char in the event. + // For example, VK_MINUS key code and '-' character + // + // We have a key char. On some non standard layouts it does not correspond to + // key code in the event. Integer keyCodeFromChar = CharToVKeyMap.get(ke.getKeyChar()); + + // Now we have a correct key code as if we'd gotten a KeyEvent for + // standard English layout + + if (keyCodeFromChar == ke.getKeyCode() || keyCodeFromChar == KeyEvent.VK_UNDEFINED) { + return e; + } + + // Farther we handle a non standard layout + if (keyCodeFromChar != null) { if (keyCodeFromChar != ke.getKeyCode()) { // non-english layout ke.setKeyCode(keyCodeFromChar); } - - //for (int i = 0; sourceComponent == null && i < WindowManagerEx.getInstanceEx().getAllProjectFrames().length; i++) { - // sourceComponent = WindowManagerEx.getInstanceEx().getAllProjectFrames()[i].getComponent(); - //} - - if (sourceComponent != null) { - if (KeyboardSettingsExternalizable.isSupportedKeyboardLayout(sourceComponent)) { - if ((ke.getModifiersEx() & (InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)) != 0 /*&& ke.getKeyLocation() == KeyEvent.KEY_LOCATION_RIGHT*/) { - // On German keyboard layout on Windows we are getting on key press - // ctrl + alt instead of AltGr - - int modifiers = ke.getModifiers() ^ InputEvent.ALT_DOWN_MASK ^ InputEvent.CTRL_DOWN_MASK; - - if (ctrlIsPressedCount > 1) { - modifiers |= InputEvent.CTRL_DOWN_MASK; - } - - if (leftAltIsPressed) { - modifiers |= InputEvent.ALT_MASK; - } - - int oldKeyCode = ke.getKeyCode(); - - //noinspection MagicConstant - ke = new KeyEvent(ke.getComponent(), ke.getID(), ke.getWhen(), modifiers, - KeyEvent.VK_UNDEFINED, ke.getKeyChar(), KeyEvent.KEY_LOCATION_UNKNOWN); - - ke.setKeyCode(oldKeyCode); - } - } } - } return ke; }