How to disable generating special characters when pressing the `alt+a`/`option+a` keybinding in Mac OS (`⌥+a` )?

MacosKeyboardKeyboard ShortcutsMacos Big-Sur

Macos Problem Overview


There is a behavior in my mac that I'm trying to disable.

When I'm in any text editor and typing a key combination using the alt/option+any letter, the output will be special characters.

For example:
the combination alt+a will generate å.
the combination alt+x will generate .

I want to cancel this behavior.
I'm a programmer and when I use my code editor I want to map some keybinding (keyboard shortcuts) to the alt key (⌥+a for example) but when I do that it doesn't execute because it generates the special characters.
I guess that the special character has a priority over my code editor shortcuts.

Do you know how can I disable this default behavior?

Thank you

Macos Solutions


Solution 1 - Macos

You can create a custom keyboard mapping with option-letters all set to BLANK using online tool from this webpage. You can create a custom mapping in several clicks out of almost any keyboard layout. Proved to work on MacOSX 10.7+ with IntelliJ Idea, Php/WebStorm, NetBeans, Eclipse.

Select "Set blank for option key" radio in the form, submit the form, and download a patched keyboard layout with "option" key feature disabled. I'm sharing the working file for standard US English keyboard layout:

After enabling this custom mapping, if you type a letter with "option" key pressed, nothing is printed to text output. But, the "option key press" is triggered by OS, and detected by your IDE. So you get exactly the same behaviour as you have for other command keys!

  1. Download the key mapping file My Layout.keylayout.
  2. Move it to ~/Library/Keyboard\ Layouts/
  3. Open System Preferences -> Language Input Methods (or Keyboard -> Input Sources)
  4. Go to Input Sources -> (hit +) -> Select Others
  5. You should find My Layout in the list and select it.

Step 4 can change slightly across MacOS versions. Please be patient to find keyboard layouts list in the settings.

Solution 2 - Macos

Here are detailed steps to Sebastian Zaha's answer. (I ended up fumbling around a bit before I got this working).

(Alternatively here is a ready made file by me)

  1. Download Ukelele
  2. You can run it directly from the .dmg file
  3. File -> New Based On Current Input Source (I had US selected)
  4. Click Modifiers button
  5. Select each modifier from list that have Left Down or Right Down in the Option column. (There could be some like Either Down OR Up too, but AFAIK you can leave those.)
  • Press the minus button for each like this
  1. Go to Keyboard menu -> Set Keyboard Name
  2. Change the name somehow to make it easier to identify
  3. Go to File -> Save as
  4. Save to ~/Library/Keyboard\ Layouts/ with suffix .keylayout
  5. Log out from your Mac OS account
  6. Log back in
  7. Go to System Preferences -> Keyboard -> Input Sources
  8. Hit the + button -> Others -> Your new layout should be available
  9. Add the new layout
  10. Possibly leave original keyboard layout too and configure some nice way to switch

Solution 3 - Macos

I was having the exact same problem, in the exact same IDE.

The solution to this is to download Ukulele from here:

http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=ukelele

In the application you can create a new keylayout using File -> New from current source. Pressing Option will show you in the place for Option-b a red colored key - meaning it's a dead key. Double clicking it will allow you to change it from a dead key to an output key. When prompted for the output you can put in the same thing (by pressing Option-b).

Thus it will output the same character but will not be considered a dead key, so Intellij can bind it as a shortcut.

To enable your new layout you must save it into your ~/Library/Keyboard Layouts (it helps if you give it a new name with Keyboard -> Set Keyboard Name), and then enable it from System Preferences -> Language & Text.

Solution 4 - Macos

Use Ctrl-Alt-<MNEMONIC>. IMHO much easier than having to install and configure a separate app.

Solution 5 - Macos

I have a solution! Place a file at: ~/Library/KeyBindings/DefaultKeyBinding.dict as:

/* ~/Library/KeyBindings/DefaultKeyBinding.dict */
 {
    /* Additional Emacs bindings */
    "~f" = "moveWordForward:";
    "~b" = "moveWordBackward:";
    "~<" = "moveToBeginningOfDocument:";
    "~>" = "moveToEndOfDocument:";
    "~v" = "pageUp:";
    "~d" = "deleteWordForward:";
    "~^h" = "deleteWordBackward:";
    "~\010" = "deleteWordBackward:";  /* Option-backspace */
    "~\177" = "deleteWordBackward:";  /* Option-delete */

    /* Escape should really be complete: */
    "\033" = "complete:";  /* Escape */        
}

It will hide the original textual input. But you can still get that by using Ctrl-Q before the combination. So Ctrl-Q Alt-f gives me ƒ for example. In fact, I'm writing this answer with the option keybindings enabled. You can also add other keys you like! Official reference: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html

Here is a good list of things you can bind to: https://www.hcs.harvard.edu/~jrus/site/selectors.html

Oh, by the way, if you bind a key to an undefined action, your application will have a memory leak and your system will run out of memory in a few seconds. Tested on el capitan, in the hard way.

Solution 6 - Macos

I had the same issue on a new Macbook with VSCode which had worked fine on my old Macbook. When I typed alt-shift-f for format I got unicode instead. I realised the difference was my old Macbook had a British keyboard setup instead of the default "ABC - Extended". Adding the British keyboard fixed the issue for me.

Solution 7 - Macos

Using the Apple JRE, the Option key combinations will work as shortcuts instead of inserting special characters.

Download link: https://support.apple.com/kb/DL1572?locale=en_US

It's an old outdated JRE (based on Java 6) but as of October 2015 it's still what seems to work best w/ my JetBrains RubyMine installation. (Anything else, the keys go back to inserting special characters.)

Solution 8 - Macos

Use ABC as input method instead of ABC-Extended, then option + [char] would be able to use the application shortcut instead of showing special character.

Solution 9 - Macos

I have found a decent workaround. I use the software Karabiner to change my right enter key to control when held down.

So what iv done is remapped the option key to option+cmd+control, as I'm not aware of any commands that use all three modifiers. Now I can map the right shortcuts without any characters. But you could also map to additional keys if required

Add this to your private.xml: (in between root)

<item>
<name>Change option Key to cmd + control + option</name>
<identifier>private.optiontoelse</identifier>
<autogen>__KeyToKey__ 
    KeyCode::OPTION_L, 
    KeyCode::OPTION_L, ModifierFlag::CONTROL_L | ModifierFlag::COMMAND_L</autogen>
<autogen>__KeyToKey__ 
    KeyCode::OPTION_R, 
    KeyCode::OPTION_R, ModifierFlag::CONTROL_R | ModifierFlag::COMMAND_R</autogen>
</item>

Then reload the xml and enable the option at the top of the 'Change Key' tab

https://pqrs.org/osx/karabiner/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionximyuView Question on Stackoverflow
Solution 1 - MacosDanView Answer on Stackoverflow
Solution 2 - MacosPeter LambergView Answer on Stackoverflow
Solution 3 - MacosSebastian ZahaView Answer on Stackoverflow
Solution 4 - MacosVictor TataiView Answer on Stackoverflow
Solution 5 - MacosWung HughView Answer on Stackoverflow
Solution 6 - MacoschookieView Answer on Stackoverflow
Solution 7 - MacosMarkWPiperView Answer on Stackoverflow
Solution 8 - MacosMichael YuView Answer on Stackoverflow
Solution 9 - MacosnicwhittsView Answer on Stackoverflow