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

50,113

Solution 1

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 2

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 3

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
  6. Go to Keyboard menu -> Set Keyboard Name
  7. Change the name somehow to make it easier to identify
  8. Go to File -> Save as
  9. Save to ~/Library/Keyboard\ Layouts/ with suffix .keylayout
  10. Log out from your Mac OS account
  11. Log back in
  12. Go to System Preferences -> Keyboard -> Input Sources
  13. Hit the + button -> Others -> Your new layout should be available
  14. Add the new layout
  15. Possibly leave original keyboard layout too and configure some nice way to switch

Solution 4

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

Solution 5

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.

Share:
50,113
ximyu
Author by

ximyu

Updated on August 07, 2021

Comments

  • ximyu
    ximyu almost 3 years

    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

  • Dan
    Dan almost 11 years
    I've made some testing and it works on 10.5 also. Usually using it for WebStorm and Idea. This increases the number of hotkeys much!
  • RussellStewart
    RussellStewart over 10 years
    works great. Also, for those who would like to further map selected option+... keys to emacs commands, as they work in terminal or linux in general, you may want to check out Emacs Mode under keyremap4macbook.
  • WestCoastProjects
    WestCoastProjects over 10 years
    This is a lot of work and only fixes one key combo in one app. I and at least some others would want to across the board disable opt as special characters input on mac.
  • WestCoastProjects
    WestCoastProjects over 10 years
    I went to the Input Sources Dialog but do not see any layouts list ? I put the file there /Users/steve/Library/Keyboard Layouts/BlankOptionKey.keylayout
  • Dan
    Dan over 10 years
    @javadba, please try walking around the settings connected with keyboard input. You should find a vertical list with lots of languages supported. I don't have Mac nearby, so I can't give a good answer to your question.
  • WestCoastProjects
    WestCoastProjects over 10 years
    @Dan Yes there is a vertical list of languages - but how does that relate to "layouts list"? There is no "My Layout" there - just .. languages..
  • WestCoastProjects
    WestCoastProjects over 10 years
    @Dan I found out how to do this - the instructions were missing a step. Should be: keyboard | Input Sources | (hit +) | Select OTHERS (that's the missing step) | (then the "My Layout" shows up)
  • Dan
    Dan over 10 years
    @javadba, I've corrected my answer. Thank you for your feedback!! Things could change with new OS versions.
  • Jaime Cham
    Jaime Cham about 10 years
    This seems to work, however it also seems to screw up shortcuts for other apps when the custom layout is selected. For example Ctrl-TAB doesn't work on Chrome anymore.
  • Dan
    Dan about 10 years
    @JaimeCham strange, this is not connected with Alt button
  • Andrew White
    Andrew White about 10 years
    The dropbox link appears broken now.
  • Frank Fang
    Frank Fang about 10 years
    All keys do not work :(
  • Frank Fang
    Frank Fang about 10 years
    Oh, I see what's wrong. You did not mention that maybe I should restart the application, like Chrome, to enable the new layout.
  • Peter Lamberg
    Peter Lamberg almost 10 years
    @javadba It wasn't that bad after I got it right. See my answer below for detailed steps which should be fast to click through.
  • Peter Lamberg
    Peter Lamberg almost 10 years
    I added an answer with detailed steps to what @SebastianZaha describes in this answer. I ended up fumbling about a bit to get it done, so hopefully it will save someone (and later me) some trouble.
  • Matt Smith
    Matt Smith almost 10 years
    Confirmed working on Yosemite DP5
  • event_jr
    event_jr almost 10 years
    I ran into problems with this solution: after disabling the special symbols, I couldn't bind some keys with ~/Library/KeyBindings/DefaultKeyBinding.dict. stackoverflow.com/a/24100077/903943 is working perfectly.
  • event_jr
    event_jr almost 10 years
    This is the only solution that worked for me and allowed me to rebind the key combos to Emacs-like commands.
  • AgmLauncher
    AgmLauncher almost 10 years
    Could not get this to work. I can add my new key layout to the list, but I cannot remove the default 'US' layout, thus it won't actually use my new key layout....
  • Kirby
    Kirby over 9 years
    Thanks! Worked for me on Yosemite and Mountain Lion. On Yosemite (10.10), adding layouts is in Language & Region, Keyboard Preferences, Input Sources
  • Sahas
    Sahas over 9 years
    @event_jr, how did you rebind them for emacs behaviour? When you hold down option and click on b, it asks for output for that combination. How do we tell it that output is to go back a word?
  • event_jr
    event_jr over 9 years
    @Sahas This answer is about stopping key from interpreted as a special character. Once you do that, you have to edit DefaultKeyBinding.dict to enable Emacs commands for specific key combos.
  • Peter Lamberg
    Peter Lamberg over 9 years
    Good to know. However this is not completely satisfactory if also the Ctrl-Alt- key combinations have functions.
  • Drew
    Drew over 9 years
    Turning on 'Leave Option blank' breaks Ctrl+/ in Emacs for me
  • Innokenty
    Innokenty about 9 years
    As for me I couldn't make this work on Yosemite: I followed all the instructions successfully, I see that in my browser for example I can not type alt+symbols, but in IDEA just nothing happens when I try to use a shortcut. I'm not sure how, I restarted it, but it seems not to pick up the info that now this key combination is blank and can be triggered as a shortcut.
  • Innokenty
    Innokenty about 9 years
    As I commented above this didn't help me to fix shortcuts in IDEA on Yosemite too. I'm afraid they changed something in newer versions and now it became not possible to fix this. I'm running IntelliJ IDEA 14.1.2 on OS X Yosemite 10.10.3
  • Peter Lamberg
    Peter Lamberg about 9 years
    @Innokenty Strange. I'm on OSX 10.10.3 and IDEA 14.1.2 and my emacs-like bindings work. I brought the IDEA config over from a windows machine and the .keylayout file was built using some older version of OSX. Could one of these be the reason? Here is my layout file.
  • Innokenty
    Innokenty about 9 years
    @PeterLamberg Wow, this one works, thank you! Maybe I excluded the modifiers in Ukelele the wrong way. I left the 'Either Down's and 'Either Down OR Up's untouched.
  • Innokenty
    Innokenty about 9 years
    Also this link might be useful for those that want to remove the default 'U.S.' layout: apple.stackexchange.com/questions/44921/…
  • Peter Lamberg
    Peter Lamberg about 9 years
    @Innokentry Thanks for responding! I'm adding the file to main post too.
  • jmcmichael
    jmcmichael about 9 years
    I was also searching for a solution to the option keymapping problem in IntelliJ/10.10.3, and found this. And it worked - thank you @PeterLamberg! I was previously using cmd-key-happy, now I'm using Karabiner to swap option/command keys, and ctrl-space to select wasn't working until I added your keymap. One thing that was nice about cmd-key-happy is that you could specify 'passthrough' for sequence like cmd-tab for app switching. I could then hit option-tab to do this with cmd-key-happy but now it doesn't appear to do anything. Have you run into an issue like this? Thanks again.
  • bgs
    bgs about 9 years
    Thank you! I use Alt+Slash so many times...
  • ARKBAN
    ARKBAN almost 9 years
    For IDE's CTRL+ALT is likely already used, so you have to reconfigure your IDE, which is equal pain to having to configure some other app.
  • duelin markers
    duelin markers over 8 years
    In OS X 10.10.5, I didn't see any "Left Down" or "Right Down" in the "Option" column: just "Either Down". I removed all those, and now have Emacs-style keybindings working in IntelliJ. I wish I understood what removing those rows meant, but since it's easy to switch input methods if I run into trouble, I'm going with it. Thanks.
  • haosdent
    haosdent about 8 years
    This is not work in 10.11 anymore. I generate a layout file in gist.github.com/haosdent/573ea124e5ea666fc576 which works in 10.11
  • Kirby
    Kirby over 7 years
    this answer is what you get if you ask JetBrains
  • Alexandre G
    Alexandre G almost 7 years
    @Innokenty If you export the layout as a bundle, then you can simply remove the other layout from preferences. If not working make sure you set script to Latin when saving bundle. Oh and this way you can keep the layout icon too.
  • Navin
    Navin about 6 years
    Didn't work for me. Instead of option+r typing ®, it now types r in IntelliJ :(
  • Amir Eldor
    Amir Eldor almost 6 years
    I tried this but still got an annoying character with Option+N for example in Intellij IDEA.
  • Bloke
    Bloke almost 6 years
    same thing here as for @Navin, option+letter now prints that letter to text output :(
  • tiktak
    tiktak about 5 years
    Generate from the website, because when I download the file from GitHub, then the characters appear in IntelliJ. Not so when I generate the file myself.
  • Bloke
    Bloke about 5 years
    @tiktak is right! I've just generated one myself using the Yes, but leave the "option" keystrokes blank. option, and it works perfectly :)) Thank you! (@Navin try like this)
  • Code Name Jack
    Code Name Jack about 4 years
    This answer helped me, Instead of ABC-Locale or ABC-Extended, I used ABC
  • ijoseph
    ijoseph over 3 years
    For Karabiner-Elements, which uses json rather than xml and is necessary for newer MacOS versions, use this template: gist.github.com/ijoseph/dd136b7bdf622bbe54f7339db052df5e
  • haosdent
    haosdent about 2 years
    @Navin Sorry that miss the message, I update my script at gist.github.com/haosdent/573ea124e5ea666fc576
  • HaterTot
    HaterTot about 2 years
    2022, macOS Monterey: for some reason it wasn't enough to clear out the modifiers that had option. I had to explicitly add in a modifier set (with +, only select "option down") at index 0. Without doing so, for some reason the alt key would trigger some other map at another index. Doing so seems to explicitly say "when option is pressed, the letters on the keyboard are the same as if option wasn't pressed".
  • SOFe
    SOFe about 2 years
    This does not disable special characters in general. I still have a chance of accidentally typing the multibyte dash instead of the ASCII -, which could lead to really confusing errors especially in languages with the -> operator.