Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISO Keyboards: Backslash and IntlBackslash "swapped" #24153

Closed
TomBurnettUK opened this issue Apr 7, 2017 · 3 comments
Closed

ISO Keyboards: Backslash and IntlBackslash "swapped" #24153

TomBurnettUK opened this issue Apr 7, 2017 · 3 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug keybindings VS Code keybinding issues keyboard-layout Keyboard layout issues macos Issues with VS Code on MAC/OS X
Milestone

Comments

@TomBurnettUK
Copy link

  • VSCode Version: 1.11.1
  • OS Version: macOS 10.12.4
  • British Keyboard Layout
  • All extensions disabled

Whenever I try to use shortcuts which use the § and ` keys, their values appear to be reversed. The keys work correctly on every other app and everywhere else within VS Code; it's specifically when they're used as shortcuts. The problem extends to when I try to rebind them as well:

image

image

(Ignore the 'shift+command', they came from taking the screenshot!)

To be clear, the 'key' value is the correct one and the 'UI' value is the incorrect one the shortcut recognises.

@alexdima alexdima added macos Issues with VS Code on MAC/OS X keyboard-layout Keyboard layout issues labels Apr 7, 2017
@alexdima
Copy link
Member

alexdima commented Apr 7, 2017

@TomBurnettUK This might be an issue in our C++ node module that reads information about the current keyboard layout. Could you please:

  • open an editor
  • press F1 > Developer: Inspect Keyboard mappings
  • save the contents to a file
  • attach the file here

I could then examine what the C++ node module determines for the [Backquote] scan code.

@TomBurnettUK
Copy link
Author

Sure! Here's the file.

KeyMappings.txt

@alexdima alexdima changed the title Incorrect key values for shortcuts Backslash and IntlBackslash "swapped" under British Keyboard Layout Apr 10, 2017
@alexdima alexdima added the keybindings VS Code keybinding issues label Apr 10, 2017
@alexdima alexdima changed the title Backslash and IntlBackslash "swapped" under British Keyboard Layout British Keyboard Layout: Backslash and IntlBackslash "swapped" Apr 10, 2017
@alexdima alexdima added the bug Issue identified by VS Code Team member as probable bug label Apr 26, 2017
@alexdima alexdima added this to the April 2017 milestone Apr 27, 2017
@alexdima alexdima changed the title British Keyboard Layout: Backslash and IntlBackslash "swapped" ISO Keyboards: Backslash and IntlBackslash "swapped" Apr 28, 2017
@alexdima
Copy link
Member

alexdima commented Apr 28, 2017

Thanks to investigation help from @jrieken and his ISO keyboard, we were able to reproduce. The root problem is simple, our native C++ node module reads the scan codes -> chars mapping correctly, but Chromium decides to "swap" the KeyboardEvent.code [Backquote] and [IntlBackslash] on OSX on ISO keyboards in order to try to stay w3c compliant.

Here is the offending code:
https://cs.chromium.org/chromium/src/ui/events/keycodes/keyboard_code_conversion_mac.mm?type=cs&q=LMGetKbdType+package:%5Echromium$&l=809

int ISOKeyboardKeyCodeMap(int nativeKeyCode) {
  // OS X will swap 'Backquote' and 'IntlBackslash' if it's an ISO keyboard.
  // https://crbug.com/600607
  switch (nativeKeyCode) {
    case kVK_ISO_Section:
      return kVK_ANSI_Grave;
    case kVK_ANSI_Grave:
      return kVK_ISO_Section;
    default:
      return nativeKeyCode;
  }
}

DomCode DomCodeFromNSEvent(NSEvent* event) {
  if (KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) {
    return ui::KeycodeConverter::NativeKeycodeToDomCode(
        ISOKeyboardKeyCodeMap([event keyCode]));
  }

  return ui::KeycodeConverter::NativeKeycodeToDomCode([event keyCode]);
}

We need to figure out a way on our side to "unswap" them...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug keybindings VS Code keybinding issues keyboard-layout Keyboard layout issues macos Issues with VS Code on MAC/OS X
Projects
None yet
Development

No branches or pull requests

2 participants