vscode-which-key icon indicating copy to clipboard operation
vscode-which-key copied to clipboard

Possible to map arrow keys?

Open theol0403 opened this issue 3 years ago • 6 comments

Hello

I have a QMK powered keyboard, meaning I can put arrow keys on a layer and don't need to use hjkl. Since I am using a custom layout, the hjkl keys are no longer on the home row.

I want to be able to map something like spc w right, where I can navigate windows with the arrow keys. This works in emacs.

Is this possible? I'm not sure how the syntax looks like in the configuration. Hopefully this is something vscode allows you to bind!

Thanks!

theol0403 avatar May 13 '21 19:05 theol0403

It is possible. See use-non-character-keys. As an example, for SPC w <right>:

  1. Add the follow bindings to your user's user keybindings.json so we can intercept the <right> key and send it as to which key.
{
    "key": "right",
    "command": "whichkey.triggerKey",
    "args": "→",
    "when": "whichkeyVisible"
}
  1. Add the following overrides to your user's settings.json so we have a entry that maps to SPC w →
"vspacecode.bindingOverrides": [
    {
        "keys": "w.→",
        "name": "Focus window right",
        "type": "command",
        "command": "workbench.action.focusNextGroup"
    }
]

But I would be a little bit hesitant to add that as the default, because up and down key can select different menu items in the QuickPick menu.

stevenguh avatar May 13 '21 21:05 stevenguh

Thank you! I missed that section in the docs. I agree adding it by default might not be ideal - maybe some configuration flag or snippet in the docs would be the best solution.

Thank you for the great plugin! Maybe I will make some doom-flavoured config in the future :eyes:.

theol0403 avatar May 14 '21 06:05 theol0403

I'm having trouble binding the up/down keys.

Simply adding

    {
        "key": "up",
        "command": "whichkey.triggerKey",
        "args": "→",
        "when": "whichkeyVisible"
    },

along with the settings entry you mentioned above does not seem to do anything. I'm aware that I kept the right arrow, but I think that it should just call the "focus window right" binding we defined earlier for the right arrow (which works).

My theory is that vscode does not allow you to bind up/down in the quick pick menu. Maybe https://github.com/microsoft/vscode/issues/98479 is related?

I'm wondering if you have any other workarounds, if I should comment on the linked issue, or if I should make a new issue.

Thanks!

theol0403 avatar May 16 '21 01:05 theol0403

Sorry. I didn't test all the arrow keys. Seems like it is evident by the issue you linked that up/down arrow are special case'd in the QuickInput. See https://github.com/microsoft/vscode/blob/main/src/vs/base/parts/quickinput/browser/quickInput.ts#L724-L741.

I don't see any workaround available unless vscode team changed how they handle those keys. Maybe try commenting on the linked issue to start?

stevenguh avatar May 17 '21 04:05 stevenguh

Just a quick note before I comment on the issue (in a few days), I found that commenting out the dom.EventHelper.stop(event, true); in the code you linked and building from source allowed the extension to override the shortcut while still allowing the key to work to navigate in other contexts.

theol0403 avatar May 17 '21 07:05 theol0403

That's interesting. I guess that's what stopping the dom event which bubbling up to shortcut handling? Anyway that's a very detailed comment on vscode 👍

stevenguh avatar May 18 '21 03:05 stevenguh