Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug keybinds in Visual Studio Code

I am trying to get the keybind for adding new cursors to work in Visual Studio Code (Ctrl+Alt+DownArrow / UpArrow). Currently pressing this combination of keys has no obvious effect, but is listed in my command palette as creating new cursors (and selecting the option from the command palette works as expected).

Therefore I am wondering if there is an easy way to work out why it isn't working, for example an output of what key combinations the editor receives and what commands it carries out on receiving a key combination?

Here is the command I am referring to (note that selecting it from palette works as shown),

enter image description here

like image 858
James Elderfield Avatar asked Sep 10 '17 11:09

James Elderfield


2 Answers

You can troubleshoot keybindings by opening the Command Palette and selecting Developer: Toggle Keyboard Shortcuts Troubleshooting

You can read more in the VS Code documentation,

To troubleshoot keybindings problems, you can execute the command Developer: Toggle Keyboard Shortcuts Troubleshooting. This will activate logging of dispatched keyboard shortcuts and will open an output panel with the corresponding log file.

You can then press your desired keybinding and check what keyboard shortcut VS Code detects and what command is invoked.

like image 67
Britt Selvitelle Avatar answered Sep 30 '22 22:09

Britt Selvitelle


I fixed my original issue by bringing up the dev tools in VSCode (Help > Toggle Developer Tools) and noticing the warning:

"Ctrl+Alt+ keybindings should not be used by default under Windows."

This was being thrown by a package unrelated to multi-cursor but highlighted the issue. It simply seems that you cannot use keybinds of that type under Windows, though I could not find any documentation on reserved Windows keybindings.

For debugging keybinds I ended up pulling down the vscode source and there is a promising looking interface IKeybindingService. I imagine a break-point in the lookupKeybindings function on a class implementing this interface would be useful for debugging keybinds, but having fixed my original issue I am not looking any further into this.

like image 26
James Elderfield Avatar answered Sep 30 '22 22:09

James Elderfield