15

Problem
When I type alt+j, I always get the character , even if I've assigned alt+j to a keyboard shortcut within VSCode.

The same is true for any other alphanumeric keys, but non-character-generating keys work fine with alt, like alt+upArrow.

Therefore, I can't use the alt key as a modifier for many keyboard shortcuts.

I realize this is normal MacOS behavior for text input, but I'm wondering:

Question
Can VSCode override / takes-precedence-over the OS, so that I can use the alt key for keyboard shortcuts?

Tried so far
I've searched for settings within VSCode and MacOS, but haven't found anything obvious. I've also edited keybindings.json, to no effect.

ultraGentle
  • 5,084
  • 1
  • 19
  • 45
  • Is [How to disable typing special characters when pressing option key in Mac OS X?](https://stackoverflow.com/questions/11876485/how-to-disable-typing-special-characters-when-pressing-option-key-in-mac-os-x) out of date? – Andrew Morton Mar 26 '20 at 15:05
  • Thanks for that link! I'd rather rely on native Mac or VSCode options than an 3rd-party intermediary, if possible. – ultraGentle Mar 26 '20 at 15:11
  • VS Code is a third-party program w.r.t. the Apple ecosystem, so you've stepped on that path already ;) – Andrew Morton Mar 26 '20 at 15:15
  • Ah, by 3rd-party, I literally mean that MacOS is (1), VSCode is (2), and I'd rather not have a (3) to keep track of if this can be done within (1) and (2). – ultraGentle Mar 26 '20 at 15:30

3 Answers3

22

Solved this as follows with no complicated keybinding file changes:

⟶ System preferences
⟶ Keyboard
⟶ Input Sources Tab
+ at bottom left
⟶ add and select Unicode Hex Input from panel on right

 ✓  Mac no longer prints anything on alt+letter|number
 ✓  enter unicode characters via alt+[code]
 ✅ Keyboard shortcuts are assignable to alt key!

ultraGentle
  • 5,084
  • 1
  • 19
  • 45
5
"terminal.integrated.macOptionIsMeta": true

Source

Bart Louwers
  • 873
  • 9
  • 28
Vlad Volkov
  • 183
  • 3
  • 5
1

If you are using mac and typed 'opt+a/p/9/...' or 'opt+shift+a/q/9..' and then got wired special characters, you find the right place.

I was using Karabiner and struggled to find the perfect solution. Open you 'karabiner.json' config file. Put the following 'Boss Rule' in the last position, if you have own binding keys, remember to put your rules before the following rule. Other apps' shortcuts seem to be override by this last rule unless you set application exception, find more about it here.

The manipulators are evaluated from the top to the bottom and the input event is manipulated only the first matched manipulator.

{
  description: 'disable all option or option+shift keys',
  manipulators: [
    {
      from: {
        any: 'key_code',
        modifiers: {
          mandatory: ['left_option'],
          optional: 'left_shift'
        }
      },
      to: [
        {
          key_code: 'vk_none'
        }
      ],
      type: 'basic'
    }
  ]
}


Save the config file and enjoy!!!

  • Another option is to exchange your "left_option" and "left_control" using Karabiner and this is the way I am using now. It feels awesome. For shortcuts, I used to set "left_option+j" to move cursor left, but now I set it to "left_control+j". But I am still pressing "left_option" in the keyboard – fullstackneo Jun 17 '23 at 02:32