Repository: microsoft/vscode (TypeScript)
Date: 2023-02-06 16:24:42+00:00
Task type: Bug Fix

Issue:
keyboard shortcuts: wrong interpretations of special keys (e.g. `[Equal]` is mistaken for `V`)
Type: <b>Bug</b>

1. Update VS Code (for me, it was from `1.74.1` to `1.75`)
2. User defined keybindings using scan codes (e.g. `[Equal]` or `[Semicolon]`) are interpreted incorrectly

![Screenshot from 2023-02-03 17-18-58](https://user-images.githubusercontent.com/44545919/216653544-7abfa3b9-1f8c-4f17-99c3-e8c54c65df78.png)

<details><summary>More details</summary>

I was literally unable to copy-paste inside VS Code because pasting was also `ctrl+v`..

VS Code version: Code 1.75.0 (e2816fe719a4026ffa1ee0189dc89bdfdbafb164, 2023-02-01T15:29:17.766Z)
OS version: Linux x64 5.15.0-58-generic
Modes:
Sandboxed: No

<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz (8 x 3899)|
|GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: disabled_off<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>skia_renderer: enabled_on<br>video_decode: disabled_software<br>video_encode: disabled_software<br>vulkan: disabled_off<br>webgl: enabled<br>webgl2: enabled<br>webgpu: disabled_off|
|Load (avg)|0, 0, 0|
|Memory (System)|15.57GB (11.48GB free)|
|Process Argv|--disable-extensions --crash-reporter-id 82449883-a908-4a7a-be3e-fc9cf8042ab0|
|Screen Reader|no|
|VM|0%|
|DESKTOP_SESSION|regolith|
|XDG_CURRENT_DESKTOP|Regolith:GNOME-Flashback:GNOME|
|XDG_SESSION_DESKTOP|regolith|
|XDG_SESSION_TYPE|x11|
</details>Extensions disabled
<!-- generated by issue reporter -->

---

superseeds #173324

---

</details>

---

### Known workarounds: 
* update to [latest Insiders](https://code.visualstudio.com/insiders/) or [latest stable 1.75.1](https://code.visualstudio.com/updates/v1_75).




Issue discussion:
related: https://stackoverflow.com/questions/75336265/vscode-says-equal-key-is-v-keyboard-layout-messed-up
I think this is not only `ctrl+v` but I have other keybindings stopped working just after this upgrade.
> I think this is not only `ctrl+v` but I have other keybindings stopped working just after this upgrade.

I adjusted the issue title accordingly. If you find out which one exactly, please let us know :)
Seriousloy annoying. Does anybody have a quick fix? beyond losing the [Equal] keybindings or downgrading versions
This is a rather urgent and serious bug :thinking: is there a way to give priority to this issue? @georglauterbach
Same here. `[Minus]` is replaced by `U` and `[Equal]` by `V`. That's really annoying.

![image](https://user-images.githubusercontent.com/41755127/216677666-ebd8659a-fbc4-44ea-ade2-b8bc0c8e64c5.png)

![image](https://user-images.githubusercontent.com/41755127/216677758-7cecf9f8-2801-420c-8092-be40317c18a3.png)

I have an affected `ctrl+equal` shortcut, remapped it to `ctrl+alt+equal`, which stays as-is. If you need a quick workaround.
> This is a rather urgent and serious bug :thinking: is there a way to give priority to this issue? @georglauterbach

I cannot adjust the issue (labels, etc.) myself, but I agree that this should have high priority.
The issue has messed up a lot of my custom shortcuts and is incredibly annoying:

- `[BracketRight]` is mapped to X.
- `[BracketLeft]` is mapped to W.
- `[Comma]` is mapped to F2.
- `[Equal]` is mapped to V.
- `[Minus]` is mapped to U.

These are the ones that have been affected for me from a quick glance. I'm shocked that this was released :0
I have the same issue on VSCodium, on a US keyboard layout

```
Version: 1.75.0
Release: 23033
Commit: d48b950f7741008f7fb375881b45188dd73ecac4
Date: 2023-02-02T22:14:58.243Z
Electron: 19.1.9
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Linux x64 6.1.6-arch1-g14-1
Sandboxed: No
```

Additionally, these keycodes are also broken:

- `[Backquote]` is mapped to F1 but not when used with `ctrl+alt+[Backquote]` (that works as intended)
- `[Backslash]` is mapped to Y on both IT and US layouts (I assume it's the same for all layouts then)
ping @alexdima; this should probably have high priority as broken keyboard shortcuts really cut the experience of using VS Code short
I'm hoping this gets a high priority. It completely messed up a lot of my key bindings.

> These are the ones that have been affected for me from a quick glance. I'm shocked that this was released :0

Released on a friday :wink: Have a nice weekend ya'll!
For me on a german layout, `cmd+y` is `cmd+#` for some reason, now I can't redo anymore.

<img width="243" alt="image" src="https://user-images.githubusercontent.com/17879327/216777139-95f224f1-0c74-4c3c-b10b-fa4637fa969c.png">

edit: just confirmed that this issue isn't present on 1.74.3

> For me on a german layout, `cmd+y` is `cmd+#` for some reason, now I can't redo anymore.
> 
> <img alt="image" width="243" src="https://user-images.githubusercontent.com/17879327/216777139-95f224f1-0c74-4c3c-b10b-fa4637fa969c.png">
> 
> edit: just confirmed that this issue isn't present on 1.74.3

Can confirm.

Pressing `[Ctrl]+[#]` on the keyboard shortcut settings page with a German keyboard adds `"key": "ctrl+[Backslash]"` to `keybindings.json`. This behavior (config write) is the same on 1.74.x as well as 1.75.0. However, the interpretation of this (config read) is different:

On 1.74.x, this *used to work*, i.e. `ctrl+[Backslash]` in the config did correspond to a physical key press of `[Ctrl]+[#]` in the editor using a German keyboard.

However, on 1.75.0 this config entry reacts to a physical keypress of `[Ctrl]+[Y]` only. Thus, VSCode does not correctly interpret the `keybindings.json` entry it wrote itself (even if written with 1.75.0, this is not a config migration problem):

- config write: `[Ctrl]+[#]` -> "ctrl+[Backslash]"
- config read: "ctrl+[Backslash]" ->  `[Ctrl]+[Y]`

Potential fix [here](https://github.com/microsoft/vscode/pull/173456).
The issue was introduced [here](https://github.com/microsoft/vscode/pull/169842).
The hashcode for scan codes and simple keys was not updated to distinguish between them.

@hamzahamidi Thank you for tracking this down! This is indeed caused by the implementations of `KeyCodeChord.getHashCode()` and `ScanCodeChord.getHashCode()`, which produce strings which overlap.

For example:
* a key code based binding like `ctrl+v` will have the hash code `100052`.
* a scan code based binding like `ctrl+[Equal]` will also have the hash code `100052`.

> Potential fix [here](https://github.com/microsoft/vscode/pull/173456). The issue was introduced [here](https://github.com/microsoft/vscode/pull/169842). The hashcode for scan codes and simple keys was not updated to distinguish between them.

When is it possible to release this hotfix? It's pretty urgent.
> When is it possible to release this hotfix? It's pretty urgent.

I'm super sorry for this regression! I'm trying to get the change into tomorrow's Insiders and we'll very likely ship it with `1.75.1`. I've updated the issue description with a potential workaround which consists of editing the scan code based user bindings to use key code.
any workaround for azerty keyboards ?



> any workaround for azerty keyboards ?

downgrading to 1.74.3 works
The fix was merged. Thanks @alexdima and Thank you @hamzahamidi for the quick fix
anyone knows when will new version release to fix 1.75 key bindings issue?
> anyone knows when will new version release to fix 1.75 key bindings issue?

Most likely with 1.75.1.
Reopening to track the merge to stable

Solution patch:
diff --git a/src/vs/base/common/keybindings.ts b/src/vs/base/common/keybindings.ts
--- a/src/vs/base/common/keybindings.ts
+++ b/src/vs/base/common/keybindings.ts
@@ -94,7 +94,7 @@ export class KeyCodeChord implements Modifiers {
 		const shift = this.shiftKey ? '1' : '0';
 		const alt = this.altKey ? '1' : '0';
 		const meta = this.metaKey ? '1' : '0';
-		return `${ctrl}${shift}${alt}${meta}${this.keyCode}`;
+		return `K${ctrl}${shift}${alt}${meta}${this.keyCode}`;
 	}
 
 	public isModifierKey(): boolean {
@@ -154,7 +154,7 @@ export class ScanCodeChord implements Modifiers {
 		const shift = this.shiftKey ? '1' : '0';
 		const alt = this.altKey ? '1' : '0';
 		const meta = this.metaKey ? '1' : '0';
-		return `${ctrl}${shift}${alt}${meta}${this.scanCode}`;
+		return `S${ctrl}${shift}${alt}${meta}${this.scanCode}`;
 	}
 
 	/**


Test patch:
diff --git a/src/vs/base/test/common/keybindings.test.ts b/src/vs/base/test/common/keybindings.test.ts
new file mode 100644
--- /dev/null
+++ b/src/vs/base/test/common/keybindings.test.ts
@@ -0,0 +1,18 @@
+/*---------------------------------------------------------------------------------------------
+ *  Copyright (c) Microsoft Corporation. All rights reserved.
+ *  Licensed under the MIT License. See License.txt in the project root for license information.
+ *--------------------------------------------------------------------------------------------*/
+
+import * as assert from 'assert';
+import { KeyCode, ScanCode } from 'vs/base/common/keyCodes';
+import { KeyCodeChord, ScanCodeChord } from 'vs/base/common/keybindings';
+
+suite('keyCodes', () => {
+
+	test('issue #173325: wrong interpretations of special keys (e.g. [Equal] is mistaken for V)', () => {
+		const a = new KeyCodeChord(true, false, false, false, KeyCode.KeyV);
+		const b = new ScanCodeChord(true, false, false, false, ScanCode.Equal);
+		assert.strictEqual(a.getHashCode() === b.getHashCode(), false);
+	});
+
+});