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 · 55 comments
Open

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

tallpants opened this issue Apr 6, 2017 · 55 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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Author

@tallpants tallpants commented Apr 7, 2017

Thanks for the workaround! 👍

@graves501

This comment has been minimized.

Copy link

@graves501 graves501 commented Apr 10, 2017

The workaround works like a charm, thanks!

@tobico

This comment has been minimized.

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

This comment has been minimized.

Copy link

@navxio navxio commented Jun 1, 2017

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

@alexdima

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

@Chillee Chillee commented Jun 21, 2017

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

@mlcamilli

This comment has been minimized.

Copy link

@mlcamilli mlcamilli commented Jan 15, 2019

I experience exactly what @olofwalker described. All of my bindings with capslock bound to ctrl do not work because of this

@my-config

This comment has been minimized.

Copy link

@my-config my-config commented Mar 15, 2019

"keyboard.dispatch": "keyCode" stopped working.

@itgoyo

This comment has been minimized.

Copy link

@itgoyo itgoyo commented Apr 7, 2019

thanks gay,"keyboard.dispatch": "keyCode", it works for me

@apahne

This comment has been minimized.

Copy link

@apahne apahne commented Apr 11, 2019

I have mapped CTRL to Caps Lock.
"keyboard.dispatch": "keyCode" is not working.

That is deep in my muscle memory. All other apps honor that. VSCode became pretty much unusable to me.

@NanoDano

This comment has been minimized.

Copy link

@NanoDano NanoDano commented Apr 22, 2019

I modified my settings.json to include "keyboard.dispatch": "keyCode", and it started working in Linux (Fedora Gnome). Thanks for that tip. I mapped my key using dconf write /org/gnome/desktop/input-sources/xkb-options "['caps:escape']". In Windows I use AutoHot key and have no issues.

@alexanderte

This comment has been minimized.

Copy link

@alexanderte alexanderte commented Apr 22, 2019

I’m using Ubuntu, and have Caps Lock mapped to Ctrl.

What worked for me was using Gnome Tweaks, and setting “Ctrl position” to “Caps Lock as Ctrl”. I initially had “Caps Lock behavior” set to “Caps Lock is also a Ctrl”, but that did not work. Also "keyboard.dispatch": "keyCode" seems to be needed.

Hope this helps!

@mlcamilli

This comment has been minimized.

Copy link

@mlcamilli mlcamilli commented Apr 22, 2019

@alexanderte super helpful, fixed my problems!

@LarnuUK

This comment has been minimized.

Copy link

@LarnuUK LarnuUK commented Jun 17, 2019

Changing Keyboard: Dispatch to KeyCode seems to have no effect for me, or at least doesn't cause settings for pointer to use the modifier Xmodmap settings.

@revgum

This comment has been minimized.

Copy link

@revgum revgum commented Jul 22, 2019

re: @alexanderte mentions using Gnome Tweaks to set "Ctrl position" and "Caps Lock behavior", I tried multiple options with the checkboxes and it only worked with the configuration in attached screenshot (along with "keyboard.dispatch": "keyCode")

gnome-tweaks

@jhpratt

This comment has been minimized.

Copy link

@jhpratt jhpratt commented Aug 29, 2019

Following up on my comment from April 2018 (~17 months ago). I just tried setting it to keyCode, and ran into the same issue as before — Ctrl + ` doesn't toggle the terminal. I've updated the version of Ubuntu, but it's otherwise the same.

@alexandrudima Is there any progress on this front? Is it something I might be able to take on?

@JamesLavin

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

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

"keyboard.dispatch": "keyCode"

Where to add this?

@LarnuUK

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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.

@aswathkk aswathkk mentioned this issue Feb 8, 2020
@jhpratt

This comment has been minimized.

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.

@jhpratt jhpratt mentioned this issue Feb 16, 2020
42 of 54 tasks complete
@kylebakerio

This comment has been minimized.

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

This comment has been minimized.

Copy link

@NanoDano NanoDano commented Mar 14, 2020

@kylebakerio Maybe you can ask for a refund.

@mahkoh

This comment has been minimized.

Copy link

@mahkoh mahkoh commented Mar 14, 2020

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

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.