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

Keyboard mappings with setxkbmap on Linux not working #23991

tallpants opened this issue Apr 6, 2017 · 88 comments
Assignees
Labels
bug help wanted keybindings linux
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?

@Stigjb
Copy link

@Stigjb Stigjb commented Feb 11, 2021

The "keyboard.dispatch": "keyCode" workaround has stopped working for me recently. The keys are still swapped in other applications, but now hitting caps lock in VS Code has absolutely no effect whether the dispatch is set to code or keyCode.

@Scoder12
Copy link

@Scoder12 Scoder12 commented Feb 23, 2021

The "keyboard.dispatch": "keyCode" workaround was working but recently it isn't working anymore.

@kylebakerio
Copy link

@kylebakerio kylebakerio commented Feb 23, 2021

Amazing. I've been following this issue for years. I don't know any other app on linux that has had so much trouble respecting this issue that I've ever interacted with--and it's a tool built specifically for developers to write code?

I guess it matters that it is built by microsoft?

@Scoder12
Copy link

@Scoder12 Scoder12 commented Feb 24, 2021

False alarm, it started working again for me 🤷

@Stigjb
Copy link

@Stigjb Stigjb commented Mar 4, 2021

It started working again for me as well 🤷

@joooooooooooooooooooooooooooooooooooosh

Stopped working for me again.

@aflag
Copy link

@aflag aflag commented Apr 9, 2021

Are there any hopes of this issue ever getting fixed? Are all chromium based apps affected? Has it been notified upstream?

@kylebakerio
Copy link

@kylebakerio kylebakerio commented Apr 9, 2021

@aflag I've never experienced this issue with any other app (including other chromium based apps) in linux. this is a vscode-only issue for me, and has been repeatedly the handful of times I've given vscode a go over the years.

@aflag
Copy link

@aflag aflag commented Apr 9, 2021

Indeed a bit weird. It seems there’s a workaround which I haven’t tested yet. Can’t say I’ve tried too many electron based apps before, though.

It took me a while to realise what the bug was, I thought vscode was dropping input from time to time. It was very confusing, until I figured out what was going on. If it’s too difficult to fix, maybe trying to identify that something may be wrong during startup and showing a popup with a suggestion to try that work around would go a long way. It’d have definitely made my life easier/less frustrating a couple days ago.

@rishadbaniya
Copy link

@rishadbaniya rishadbaniya commented Apr 14, 2021

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

now this thing works

@gorilskij
Copy link

@gorilskij gorilskij commented Apr 26, 2021

I'm swapping Caps Lock and Backspace and the keyCode option has recently stopped working (Ubuntu 20.04, code 1.55.2)

@fahadbr
Copy link

@fahadbr fahadbr commented Apr 27, 2021

this is also a problem for me using setxkbmap settings. i started looking into using interception-tools combined with caps2esc (https://gitlab.com/interception/linux/tools) as an alternative set up and it seems to work with vscode. (capslock works as escape again)

I would suggest people looking into interception-tools as a workaround

@AntonOfTheWoods
Copy link

@AntonOfTheWoods AntonOfTheWoods commented Jul 19, 2021

@alexdima you are still assigned to this ticket, and we haven't seen any action in a while. I see the W3C keyboard-map has a draft version from March of this year.

Might one option be to try and detect that some xkb fooery is going on and alert the user to look at a FAQ about this issue, if we still need to wait for a proper fix? It's little niggles like this that keep us zealots from becoming full converts :-).

@olejorgenb
Copy link

@olejorgenb olejorgenb commented Jul 21, 2021

What's the rationale for dispatching based on "code"? Does this means that dvorak and international users have the same physical hotkeys as qwerty and americans also? (which is arguable a good thing, but possibly quite confusing)

I assume "code" means keycode and "keycode" means keysym in X11 lingo.

@truly-irham
Copy link

@truly-irham truly-irham commented Aug 21, 2021

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

now this thing works

Thanks for quoting this. I really don't know why the workaround "keyboard.dispatch": "keyCode" in settings.json doesnt sync with the gui settings. It's great if someone could clarify this perhaps :/ I use arch btw

rsookram added a commit to rsookram/dotfiles that referenced this issue Aug 31, 2021
@diogogmt
Copy link

@diogogmt diogogmt commented Sep 5, 2021

Switching the dispatch mode to keyCode is working again; "keyboard.dispatch": "keyCode"

@MossabDiae
Copy link

@MossabDiae MossabDiae commented Sep 28, 2021

I'm using colemak , vscode didn't respect capslock as backspace which I set using setxkbmap , setting "keyboard.dispatch": "keyCode" did work but all the shortcuts were remapped based on the new layout which was uncomfortable .
the solution I did was :

  • setting keyboard.dispatch back to code
  • manually setting capslock to delete characters in keybindings.json (Preferences: Open keyboard shortcuts (JSON))
    {
        "key": "CapsLock",
        "command": "deleteLeft",
        "when": "editorFocus"
    },

I'm sure this issue will remain open until I show it to my grandson one day, I'm 24 ...

@kylebakerio
Copy link

@kylebakerio kylebakerio commented Sep 29, 2021

I just drop in to watch the fire burn every time I get a new notification. This issue is literally the reason I don't give VScode a real chance and stick with sublime, not willing to deal with it every time I re-install. caps lock as ctrl being seamless matters more to me.

@aflag
Copy link

@aflag aflag commented Nov 5, 2021

@kylebakerio it's free software, you can always fix it yourself and make lots of people happy.

@kylebakerio
Copy link

@kylebakerio kylebakerio commented Nov 5, 2021

I am not invested in this project. There are other editors. People rave about VS code, it was the hottness for a while, I wanted to give it a shot. It's not my field of expertise, so I'd be very inefficient getting up to speed on this. I also frankly have my own projects, work, and open source projects I contribute to. Just not in the cards for me.

It's surprising that a project sponsored by Microsoft doesn't have their shit together and prioritize what to me is fixing a bug in something ground level--getting keyboard mappings handled right in a code text editor on linux. I've never encountered this bug in another project on linux, it just isn't hard to respect key mappings in a vanilla gnome environment... And if it is, it doesn't speak well of their code architecture and design choices.

I feel like a bit of a troll here on this thread now, but it's become some kind of sad trash fire to watch, kind of can't help it. The last time I had this experience was watching the Chromium "bug report" for the garbage built-in hotkey that was present for years that made backspace = "go back" history navigation if you weren't in an active text field... which meant if you accidentally lost focus on text field (say, but tapping your mouspad with your palm on a laptop while typing) and hit backspace, you could lose all you had typed.

For years I watched the conversation rage on about this. I just sat in disbelief that such a moronic default couldn't be fixed. They finally did! couple years back. my god. anyways, same as here, would just pop in when I'd get email notifications as the conversation accumulated back and forth, year after year.... This bug has was reported in ubuntu 16.04! We're in the 21.10 era now! Jesus!

@alexdima
Copy link
Member

@alexdima alexdima commented Nov 10, 2021

I am sorry that it takes us a long time to fix this issue. The problem is that we are not X11 experts, and that our time is very limited and split between other issues. Unfortunately, we don't really get any community contributions in this area. I can only guess that is because the underlying node module is written in C++ and a contributor would need to be an expert in or at least understand the inner workings of X11.

Last month I spent about 3 days (!!) just reading the X11 specification such that I could fix:

You can find the changesets I did at https://github.com/microsoft/node-native-keymap and assess how easy or complex doing them is:

We also need to improvise, for example we now have a new thread running that is just listening to X11 keyboard state change events (in parallel to whatever Chromium is doing with X11). Is that a good design? Is that a bad design? We don't know, because we're not experts in X11. We also got some ugly freezes because of trying to join that thread (e.g. #135108), so that's why we try to ask for community help.

Contributing with comments that do not contain technical content is not helpful in this particular case. Please take a moment and consider the following positive ways in which you can contribute:

  • review the C++ code
  • create a PR that fixes a problem (e.g. memory leaks?)
  • create a PR that implements a new feature in this area (e.g. wayland support)
  • read the X11 / wayland spec and comment with technical content or links that point us to what we should be doing

To clarify, there is always the workaround to use "keyboard.dispatch": "keyCode", it is not the case that this issue does not have a workaround. If "keyboard.dispatch": "keyCode" does not work, then it means that the setxkbmap you have defined also does not work in any Chromium based browsers.

@kylebakerio
Copy link

@kylebakerio kylebakerio commented Nov 10, 2021

Hey, I'm sympathetic to that, interesting to hear that it isn't somewhere clearly defined as a best practice. Atom is another chromium based code editor--does it not exhibit this bug? If so, could one not look at how they've implemented it?

However

If "keyboard.dispatch": "keyCode" does not work, then it means that the setxkbmap you have defined also does not work in any Chromium based browsers.

This doesn't seem to be true, as I use chrome as a power user, and never have the issues I've seen in VScode, including with this setting. ¯\_(ツ)_/¯

@akosfekete
Copy link

@akosfekete akosfekete commented Feb 11, 2022

Another workaround for this could be using kbct to remap keys instead of setxkbmap (it works on a lower level and even supports Wayland). It's not a one-to-one replacement, but it solved a bunch of issues for me (it requires the uinput kernel module to be loaded though)

@kylebakerio
Copy link

@kylebakerio kylebakerio commented Mar 9, 2022

For whatever it's worth, an interesting VSCode extension made me give vscode yet another try.

I'm on pop 21.10 (an ubuntu variant, with gnome), using the same gnome-set caps-lock-as-control I've always had, and it's working as far as I can tell--so, progress!

I used to also have multiple languages installed, and that had also caused a subtle weird bug--don't have multilang set for now, so can't verify that issue is gone, but just thought I'd pop in and throw that out there.

@haoadoreorange
Copy link

@haoadoreorange haoadoreorange commented May 3, 2022

@alexdima, I have ctrl J set to workbench.action.quickOpenNavigateNext (vim nav) and also have GNOME Make Caps Lock an Ctrl, so I can press caps J to navigate as such.

In my case the navigation does work so I suppose it's not a key dispatch problem. However, workbench.action.quickOpenNavigateNext is supposed to select the option on key release and indeed using ctrl J does so but caps J does not, it only moves the selection.

What can be the issue here that blocks the "choose" action ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help wanted keybindings linux
Projects
None yet
Development

No branches or pull requests