177

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

Aviv Hadar
  • 330
  • 4
  • 8
ximyu
  • 2,489
  • 3
  • 19
  • 16
  • what is your app doing? if you want to disable option keys in an application where the user is typing in text, your International users are going to be very unhappy with you and your app. Or is this for a game or is the window / view doing something else? – Michael Dautermann Aug 09 '12 at 03:49
  • 36
    I'm using IntelliJ and I would like to simulate emacs keyboard shortcuts and I mapped meta to option key. But when I press, say, option-b, I did get the expected behavior as it is interpreted as a special character. – ximyu Aug 09 '12 at 07:03
  • 3
    If I use option key as a modifier, I can define even more shortcuts in my IDE, which sugnificantly boosts my productivity. – Dan Apr 16 '13 at 09:15
  • 44
    It's simply ridiculous how hard are such simple actions on Macs. Placed a wrong app in launcher - good luck removing it with SQL statements; want to disable some stupid shortcut - start downloading and testing zillion solutions which are not consistent across OS versions. God, why did I buy this awful computer? – Vasiliy May 07 '16 at 06:11
  • 3
    This works for me : http://superuser.com/a/942256/535138 – 김민준 Feb 10 '17 at 06:44
  • 5
    For people having problem on terminal, follow this instruction -> https://superuser.com/questions/496090/how-to-use-alt-commands-in-a-terminal-on-os-x – A-letubby May 17 '18 at 04:22
  • 1
    This is an essence of Apple solutions. Shiny and unusable for anything Apple did not think of. – Ondra Žižka Nov 15 '19 at 12:31

9 Answers9

96

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.

Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564
Dan
  • 55,715
  • 40
  • 116
  • 154
  • 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! – Dan Jul 25 '13 at 11:26
  • 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. – RussellStewart Jan 07 '14 at 18:17
  • 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 – WestCoastProjects Jan 25 '14 at 22:02
  • @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. – Dan Jan 27 '14 at 21:18
  • 1
    @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 Feb 07 '14 at 04:40
  • @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) – WestCoastProjects Feb 07 '14 at 04:44
  • 1
    @javadba, I've corrected my answer. Thank you for your feedback!! Things could change with new OS versions. – Dan Feb 10 '14 at 15:14
  • 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. – Jaime Cham Mar 10 '14 at 15:16
  • @JaimeCham strange, this is not connected with `Alt` button – Dan Apr 14 '14 at 11:26
  • 5
    The dropbox link appears broken now. – Andrew White Apr 21 '14 at 22:21
  • All keys do not work :( – Frank Fang May 02 '14 at 03:33
  • Oh, I see what's wrong. You did not mention that maybe I should restart the application, like Chrome, to enable the new layout. – Frank Fang May 02 '14 at 03:39
  • Confirmed working on Yosemite DP5 – Matt Smith Aug 06 '14 at 18:23
  • I ran into problems with this solution: after disabling the special symbols, I couldn't bind some keys with `~/Library/KeyBindings/DefaultKeyBinding.dict`. http://stackoverflow.com/a/24100077/903943 is working perfectly. – event_jr Aug 07 '14 at 13:33
  • 2
    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.... – AgmLauncher Aug 10 '14 at 16:44
  • Thanks! Worked for me on Yosemite and Mountain Lion. On Yosemite (10.10), adding layouts is in Language & Region, Keyboard Preferences, Input Sources – Kirby Oct 30 '14 at 18:02
  • Turning on 'Leave Option blank' breaks Ctrl+/ in Emacs for me – Drew Jan 17 '15 at 23:28
  • 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 May 06 '15 at 15:32
  • 13
    This is not work in 10.11 anymore. I generate a layout file in https://gist.github.com/haosdent/573ea124e5ea666fc576 which works in 10.11 – haosdent Mar 07 '16 at 08:12
  • 2
    Didn't work for me. Instead of option+r typing `®`, it now types `r` in IntelliJ :( – Navin Apr 05 '18 at 23:39
  • 1
    same thing here as for @Navin, `option`+letter now prints that letter to text output :( – Bloke Aug 09 '18 at 11:08
  • 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. – tiktak Mar 26 '19 at 22:21
  • 1
    @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) – Bloke Apr 03 '19 at 22:58
  • @Navin Sorry that miss the message, I update my script at https://gist.github.com/haosdent/573ea124e5ea666fc576 – haosdent Mar 22 '22 at 17:55
52

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
Peter Lamberg
  • 8,151
  • 3
  • 55
  • 69
  • 3
    This is the only solution that worked for me and allowed me to rebind the key combos to Emacs-like commands. – event_jr Aug 07 '14 at 13:34
  • @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? – Sahas Jan 15 '15 at 11:33
  • @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. – event_jr Jan 15 '15 at 13:29
  • 1
    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 – Innokenty May 06 '15 at 16:30
  • 2
    @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.](http://pelam.fi/osx/USKeylayout_custom_no_alt.keylayout) – Peter Lamberg May 07 '15 at 05:11
  • @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 May 07 '15 at 10:22
  • Also this link might be useful for those that want to remove the default 'U.S.' layout: http://apple.stackexchange.com/questions/44921/how-to-remove-or-disable-a-default-keyboard-layout?newreg=9b119b3cbcbf41f9948b58b551b83865 – Innokenty May 07 '15 at 11:06
  • @Innokentry Thanks for responding! I'm adding the file to main post too. – Peter Lamberg May 08 '15 at 10:57
  • 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. – jmcmichael May 09 '15 at 14:41
  • Thank you! I use Alt+Slash so many times... – bgs May 09 '15 at 19:19
  • 1
    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. – duelin markers Aug 24 '15 at 17:17
  • @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. – Alexandre G Jul 01 '17 at 08:14
  • 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". – HaterTot Apr 13 '22 at 22:20
40

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.

juan.facorro
  • 9,791
  • 2
  • 33
  • 41
Sebastian Zaha
  • 677
  • 7
  • 7
  • 20
    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 Jan 25 '14 at 21:51
  • @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 Jun 07 '14 at 17:57
  • [I added an answer with detailed steps](http://stackoverflow.com/a/24100077/1148030) 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. – Peter Lamberg Jun 07 '14 at 17:59
15

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

Victor Tatai
  • 191
  • 1
  • 3
  • 3
    Good to know. However this is not completely satisfactory if also the Ctrl-Alt- key combinations have functions. – Peter Lamberg Jan 15 '15 at 19:33
  • 4
    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. – ARKBAN Aug 10 '15 at 14:53
  • this answer is what you get if you ask JetBrains – Kirby Nov 30 '16 at 18:49
11

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.

chookie
  • 441
  • 6
  • 12
9

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.

Wung Hugh
  • 211
  • 3
  • 6
3

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.

Michael Yu
  • 69
  • 3
  • 1
    This answer helped me, Instead of ABC-Locale or ABC-Extended, I used ABC – Code Name Jack Mar 28 '20 at 19:46
  • 1
    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. – SOFe Apr 27 '22 at 06:01
2

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.)

MarkWPiper
  • 863
  • 8
  • 6
0

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/

nicwhitts
  • 190
  • 1
  • 3
  • 22
  • For Karabiner-Elements, which uses `json` rather than `xml` and is necessary for newer MacOS versions, use this template: https://gist.github.com/ijoseph/dd136b7bdf622bbe54f7339db052df5e – ijoseph Nov 09 '20 at 06:06