145
4

9 回答 9

87

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.

于 2013-04-15T16:02:43.500 回答
48

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
于 2014-06-07T17:55:50.647 回答
37

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.

于 2012-09-05T18:34:04.753 回答
12

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

于 2014-11-12T20:33:00.740 回答
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.

于 2015-12-22T05:47:32.677 回答
8

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.

于 2016-12-19T09:03:51.900 回答
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.)

于 2015-10-23T05:45:36.817 回答
2

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.

于 2017-02-23T08:34:31.033 回答
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/

于 2016-01-11T20:11:17.910 回答