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

Keyboard mappings with `setxkbmap` on Linux not working #23991

Open
tallpants opened this issue Apr 6, 2017 · 61 comments
Open

Keyboard mappings with `setxkbmap` on Linux not working #23991

tallpants opened this issue Apr 6, 2017 · 61 comments
Assignees
Milestone

Comments

@tallpants
Copy link

@tallpants tallpants commented Apr 6, 2017

  • VSCode Version: 1.11.0
  • OS Version: Ubuntu 16.04

I have my Caps Lock key bound to Escape using setxkbmap on Linux. This worked fine till 1.10, but broke with 1.11. At first I thought it was an issue with the VSCodeVim extension, but the issue persists with all the other Vim extensions on the marketplace as well. Pressing the escape button still works as expected.

The binding is still respected everywhere else in the operating system, it's only Visual Studio Code that ignores it for some reason.

Steps to Reproduce:

  1. Run setxkbmap -option caps:escape (binds caps to escape for the duration of the session)
  2. Hitting caps lock when in insert mode (with a Vim extension like VSCodeVim installed) no longer puts you normal mode.
  3. Hitting escape still works as expected and puts you in normal mode.
@jspaine
Copy link

@jspaine jspaine commented Apr 6, 2017

Same, with swapescape. Oddly caps lock works as escape to cancel in the keybinding editor, and either caps lock or escape cancel the F1 menu. Tried disabling all extensions, wiping user settings and using an empty workspace to no avail.

I have problems with numpad keys too. With num lock off they do nothing, but work as number keys with it on. If I press a direction with numpad off, nothing happens, but then turn it on and type a number and the cursor will move and then put the number.

In the keyboard shortcuts editor numpad PgDn, for example, shows up as numpad3 whether num lock is on or off.

@alexdima
Copy link
Member

@alexdima alexdima commented Apr 6, 2017

This is something that might be broken by us dispatching based on scan codes. I am sorry about it, I need some time to investigate how these options should be handled. i.e. should Chromium handle these mappings or should we do it at the application layer.

Workaround to switch VS Code to dispatch based on key code again. Add the following setting:
"keyboard.dispatch": "keyCode" and restart VS Code

@tallpants
Copy link
Author

@tallpants tallpants commented Apr 7, 2017

Thanks for the workaround! 👍

@graves501
Copy link

@graves501 graves501 commented Apr 10, 2017

The workaround works like a charm, thanks!

@tobico
Copy link

@tobico tobico commented May 8, 2017

I have a similar issue, with my Caps Lock bound to Control, where Code is unable to autoclose the quick open window when pressing Ctrl+Tab and then releasing Control. I've tested the workaround and it does not solve this issue.

Note: this appears to be specifically an issue with detecting the modifier key. Caps+Tab still launches the quick open just fine, and I have other remapped key bindings for arrow key movements that also work fine.

@navxio
Copy link

@navxio navxio commented Jun 1, 2017

this workaround isn't working for me on vscode 1.12.2-1..

@alexdima
Copy link
Member

@alexdima alexdima commented Jun 2, 2017

@navdeepio Can you please follow our troubleshooting guide at https://github.com/Microsoft/vscode/wiki/Keybindings#troubleshoot

If nothing in there works, then please proceed to create a new issue using the steps in the "I have tried all of the above" section.

@Chillee
Copy link

@Chillee Chillee commented Jun 21, 2017

@alexandrudima Do you guys plan on fixing this issue at some point? Or is the workaround satisfactory as a long term solution?

@alexdima
Copy link
Member

@alexdima alexdima commented Jun 21, 2017

@Chillee This method needs to be enhanced to account for setxkbmap customizations and then we might need some tweaks here to cover mappings of those scan codes

@Chillee
Copy link

@Chillee Chillee commented Jun 21, 2017

Is it tricky or is it feasible as a first time contribution?

@JamesLavin
Copy link

@JamesLavin JamesLavin commented Oct 9, 2019

I found a partial workaround that might help other vim users. I tweaked the idea in https://dev.to/karlredman/navigate-your-vscode-like-its-1999-the-vim-way-3632 by adding the following to ~/.config/Code/User/keybindings.json:

    {
      "key": "capslock",
      "command": "extension.vim_escape",
      "when": "editorTextFocus && vim.active && vim.mode == 'Insert'"
    },

CapsLock is now triggering Esc to get me out of Vim's insert mode, but it's also toggling CapsLock, so I have to hit CapsLock a second time to undo that. (I tried using multi-command, https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command, to automatically call CapsLock a second time, but capslock doesn't seem callable as a command.)

This shouldn't be this hard. Sigh.

@sholderbach
Copy link

@sholderbach sholderbach commented Oct 16, 2019

I found similar key rebinding problems with the new great jupyter notebook editor of the python extension.
The "keyboard.dispatch": "keyCode"setting is not correctly respected when using Esc mapped on the Caps Lock key to leave the jupyter notebook edit mode.

microsoft/vscode-python#8020

Yet in the general editor and dialogs it works for me without a problem

@itachi-19
Copy link

@itachi-19 itachi-19 commented Dec 22, 2019

"keyboard.dispatch": "keyCode"

Where to add this?

@LarnuUK
Copy link

@LarnuUK LarnuUK commented Dec 22, 2019

"keyboard.dispatch": "keyCode"

Where to add this?

Open the settings (ctrl+,), and search for Dispatch. Or click the Open Settings (JSON) button (top right, shown below), and put the setting in your JSON (it is assumed you understand how to edit a JSON file):

image

@itachi-19
Copy link

@itachi-19 itachi-19 commented Dec 22, 2019

"keyboard.dispatch": "keyCode"

Where to add this?

Open the settings (ctrl+,), and search for Dispatch. Or click the Open Settings (JSON) button (top right, shown below), and put the setting in your JSON (it is assumed you understand how to edit a JSON file):

image

Thanks a lot :)

@NeoScaler
Copy link

@NeoScaler NeoScaler commented Jan 28, 2020

This bug is still present, but the workaround also still works for me. I use the Workman-P keyboard layout, which has Backspace on Caps Lock.

@jpaniagualaconich
Copy link

@jpaniagualaconich jpaniagualaconich commented Jan 29, 2020

The Dell XPS 13 7390 has a different home/end/pgup/pgdn layout than previous models.
To try and get a similar experience on the 7390, I remapped Home, End, Page Up and Page Down to AltGr+Left, AltGr+Right, AltGR+Up and AltGr+Down. It works with both "keyboard.dispatch": "code" and "keyboard.dispatch": "keyCode".

Problem is that the "original" PgUp and PgDn keys that I thought I disabled are still working on Electron apps, even though they're disabled for all the non electron apps. This is what xev shows for the disabled PgDn:

    KeyRelease event, serial 37, synthetic NO, window 0x6600001,
    root 0x136, subw 0x0, time 1695289, (141,560), root:(249,662),
    state 0x0, keycode 117 (keysym 0x0, NoSymbol), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

NoSymbol is not taken into account somehow and vscode still turns keycode 117 into a page down.

I can work around it by directly using setkeycodes but it would be awesome if I didn't need to.

@jhpratt
Copy link

@jhpratt jhpratt commented Feb 16, 2020

For reference, my previous comment is still correct. Using keyCode does not work for me. Doing Ctrl + ` does not open the terminal as would be expected; neither of those keys are affected in any way by my keymapping. The extent of what I'm doing is having a British layout with minor modifications via Gnome.

@kylebakerio
Copy link

@kylebakerio kylebakerio commented Mar 14, 2020

This is unbelievable. Only project I know of that has this problem. Never had an issue before. And a project this size, for programmers, still hasn't fixed this after years?

Embarrassing.

@NanoDano
Copy link

@NanoDano NanoDano commented Mar 14, 2020

@kylebakerio Maybe you can ask for a refund.

@mahkoh
Copy link

@mahkoh mahkoh commented Mar 14, 2020

@kylebakerio Maybe don't use Microsoft software on linux.

@ahmaddynugroho
Copy link

@ahmaddynugroho ahmaddynugroho commented Apr 19, 2020

This is how I make Caps Lock an additional Esc for vim extension in vscode in POP!_OS 19.10:

  1. "sudo apt install gnome-tweaks"
  2. "gnome-tweaks"
  3. go to "Keyboard & Mouse" and click on "Additional Layout Options"
  4. inside "Caps Lock Behavior" choose "Make Caps Lock an Additional Esc"
  5. go to vscode "File" then "Preferences" then "Settings"
  6. Type "dispatch"
  7. choose "keyCode"
  8. done
@kylebakerio
Copy link

@kylebakerio kylebakerio commented Apr 20, 2020

For whatever it's worth, giving vscode another try after all these years, now on a clean debian 10 install, with a less complex keyboard setup (haven't gotten around to it), it seems to work... Only thing I've done is set caps lock to be ctrl using gnome-tweaks.

... until I tried setting a custom hotkey that is a default in sublime text, which is auto-indent on paste. When I tried to set to ctrl+shift+v, it somehow got confused by the capslock being a control again, and started making it so that I'd have to hit my hotkeys twice for them to work. I noticed some funniness with the input reading, it noticed it was capslock and didn't respect that it should ignore it is capslock and that it is just a ctrl.

I quickly just turned it off and manually indent things for now. I'm in the middle of a project, so I'm just giving vscode a chance for now.

Given this, I imagine if I had all my language settings and key modifiers, it still would have trouble dealing with keyboard inputs.

Maybe when my current sprint is done I'll spend some time getting to know vscode and trying to give it a chance, but this is just not a good sign.

@muhymenulhaque
Copy link

@muhymenulhaque muhymenulhaque commented May 2, 2020

Thanks, It solved my problem as well. Awesome!

@tkkcc
Copy link

@tkkcc tkkcc commented May 17, 2020

Hi, @sholderbach. Have you made it work in jupyter?

I am trying to map capslock to escape in jupyter notebook ui. In default keybings.json there is

{ "key": "escape", "command": "notebook.cell.quitEdit","when": "inputFocus && notebookEditorFocused" },

In self keybings.json, Changing escape to ctrl+capslock works, while changing to capslock fails. Also tried toggling "keyboard.dispatch": "keyCode"

@trululu96
Copy link

@trululu96 trululu96 commented Sep 16, 2020

The workaround stopped working randomly, It did not improve after a reinstall. It particularly stopped working while on jupyter notebooks, on the rest of the app it works fine.

Version: 1.49.0
Commit: e790b93
Date: 2020-09-10T13:20:50.359Z
Electron: 9.2.1
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Linux x64 5.4.0-7642-generic

@i-oliva
Copy link

@i-oliva i-oliva commented Oct 28, 2020

setxkbmap -option lv3:rwin_switch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.