visual-studio-codekeyboard-eventshotkeyskeyboard-layout

Ctrl + ' (single quote) does not send a key sequence on keydown, and VSCode can't toggle line comment


I am trying to toggle line comment in VSCode, but the command isn't working. When the keyboard layout on Windows is Norwegian QWERTY, then the keyboard shortcut is mapped to ctrl+' (or ctrl+oem_2). When trying to assign the keyboard shortcut manually, i figured out that the ' key is not being registered when it is pressed in combination with the ctrl key.

When running the command Developer: Toggle Keyboard Shortcuts Troubleshooting according to the keybinding troubleshooting guide, and i press ctrl+' i see this output:

2023-11-07 10:46:12.931 [info] [KeybindingService]: / Soft dispatching keyboard event
2023-11-07 10:46:12.931 [info] [KeybindingService]: \ Keyboard event cannot be dispatched
2023-11-07 10:46:12.931 [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control
2023-11-07 10:46:12.931 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl')
2023-11-07 10:46:12.931 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase.
2023-11-07 10:46:13.551 [info] [KeybindingService]: + Ignoring single modifier ctrl due to it being pressed together with other keys.

This output suggests that VSCode does not register the ' key in the combo. This is not a VSCode specific issue, as i can see the same behavior at https://w3c.github.io/uievents/tools/key-event-viewer.html

enter image description here

Here we can see that there is no keydown event created for the ' key, and according to the keybinding troubleshooting guide, if VSCode doesn't receive a good key combination, i have to configure my OS or drivers to release that key combination to applications.

The ctrl+k ctrl+c shortcut works to add a comment and i know i can assign the toggleLineComment command to another shortcut, but it would be best to use the same shortcut across layouts, and that this can be done with a single shortcut instead of multiple chords.

How can I configure Windows, my drivers or my keyboard layout to send a keydown event for ' when ctrl+' is pressed?


Solution

  • The problem was that I had 1Password application installed, and when going to Settings > General > "Autofill:" it was mapped to ctrl+\. Removing this mapping fixed the issue.

    1Password says that this is a known issue. They don't know when this will be fixed, but you should keep an eye on the 1Password Releases page to see if this is fixed.