Keyborad remap issue with Atom


Hi all,
I just started using Atom yesterday. But I have experienced some issues with Atom.

I remapped my keyboard using xmodmap. My remap is as follows:
remap Backspace key on keyboard as Tab
remap Capslock key on keyboard as Backspace

When I tried to use Atom, it seems that when I pressed Backspace key or Capslock key on my keyboard,
both of them are interpreted as Backspace.

I have run:
document.addEventListener(‘keydown’, e => console.log(e), true)

in developer tool console.
The output of the above command when i pressed Backspace key and Capslock key is:

Backspace key:
KeyboardEvent {isTrusted: true, key: “Tab”, code: “Backspace”, location: 0, ctrlKey: false…}

Capslock key:
KeyboardEvent {isTrusted: true, key: “Backspace”, code: “CapsLock”, location: 0, ctrlKey: false…}

So that’s where things go weird. It seems that the Atom actually can get the correct meaning of each key.

Anyone knows how to fix this? Thanks!




Hey again!

Can you show the full output from the console.log? There should be more information if you click the little triangle on the left.



Actually I think there is enough information in what you posted to understand what is going on.

atom-keymap uses KeyboardEvent.key to check which key is being pressed. Except for backspace and space which uses KeyboardEvent.code. So if the KeyboardEvent.code is Backspace we resolve it to backspace and for the other key we use KeyboardEvent.key causing both to be resolved as backspace.

To work around this problem it should be enough to add the following keystroke resolver in your script:

atom.keymaps.addKeystrokeResolver ({event}) ->
  if event.code is 'Backspace' and event.key is 'Tab' and event.type isnt 'keyup'
    return 'tab'

I’m not sure why we resolve Backspace using KeyboardEvent.code. It might have been because that field was incorrect in a previous version of chrome and upgrading Electron has fixed that. On my keyboard layout it looks like we can remove this.

This logic was added to work around a bug where pressing Ctrl-Backspace resolved incorrectly depending on Num Lock, Scroll Lock and Caps Lock states. I can’t turn Scroll Lock off on this computer to check if it’s still an issue on the latest version of Electron. /cc:



This solution works! Thanks!
BTW, I am considering to change the shortcuts of Atom to Vim or Emacs style. Will this configuration affect my Vim or Emacs configuration?



It seems that this configuration will affect combination keys including tab.
I add following line into my keymap.cson file:
‘ctrl-tab’: ‘pane:show-next-recently-used-item’
‘ctrl-shift-tab’: ‘pane:show-previous-recently-used-item’

But it doesn’t work.



By the way, I am using atomic-emacs right now.




This will not affect any changes you do to your keymap it just corrects the way your keys are resolved. ctrl-tab and ctrl-shift-tab are already bound to those commands but they also have the keyup modifier. To change them you need to also unset the core binding, see this FAQ post: I want Ctrl-Tab to work like it used to. How do I do that?

For Vim style I can recommend the vim-mode-plus package or if you want to configure it yourself check out the Keymaps In-Depth section of the Atom Flight Manual.



I have done the steps in that post. But it still doesn’t work.
Will the emacs mode be the reason why it doesn’t work?



What do you see if you open the keybinding resolver using ctrl-. and pressing ctrl-tab and ctrl-shift-tab? Can you upload a screenshot?



When I type the Ctrl-Tab in Atom, the output of the Keybinding Resolver is

When I type Ctrl-Shift-Tab, the output of Keybinding Resolver is:

It seems that Atom didn’t recognize the key combinations when the combination include Tab.




I understand what is wrong now that I see the keybinding resolver. The keystroke resolver I wrote only returns tab and doesn’t check for modifiers to add those to the generated keystroke. Sorry about that :blush:

Something like this should work:

atom.keymaps.addKeystrokeResolver ({keystroke, event}) ->
  if event.code is 'Backspace' and event.key is 'Tab'
    keystroke.replace('backspace', 'tab')

keystroke in this function is the keystroke Atom recognized for these keys. Since Atom incorrectly resolves backspace when it should be tab we replace backspace with tab and return the result of that.

Let me know if you still have problems with this and I will be happy to help :slightly_smiling_face:



It works! Thanks!