1

I love the swipe gesture but I recently switched from a Magic Mouse to a gaming mouse which is non multitouch. For the back command, Safari only offers a straight keyboard-only shortcut or the multitouch swipe gesture.

For the back command, how can I create a hybrid keyboard+mouse shortcut, like alt-left click? It has to be left click + some one-hand keyboard stroke.

I forgot to mention, I am left handed therefore I need key strokes on the left hand side of the keyboard.

1
  • Please add the current shortcut of the back command in Safari you want to replace? cmd+[? Being left-handed I would expect you to use the mouse with the left hand and a key stroke on the right hand side of the keyboard...
    – klanomath
    Commented Jan 15, 2016 at 22:46

1 Answer 1

1

To make this work you have to use a third party tool: Karabiner.

In the example below hitting the left alt key once generates one back command in Safari (only). An additional mouse click is not needed.

You can use the left option/alt key as usual otherwise.

  1. Download, install and open Karabiner
  2. Open in the menulet Karabiner -> Preferences
  3. Open the tab Misc & Uninstall
  4. Hit the button Open private.xml
  5. Open the file private.xml with an appropriate editor
  6. Enter the customized keycode

    <?xml version="1.0"?>
    <root>
        <item>
            <name>Option_L to Option_L</name>
            <appendix>(+ When you type Option_L only without other modifiers, send Command+[ in Safari)</appendix>
            <identifier>remap.altL2altL_backward_nomod</identifier>
            <only>SAFARI</only>
            <autogen>__KeyOverlaidModifier__ KeyCode::OPTION_L, KeyCode::OPTION_L, KeyCode::BRACKET_LEFT, ModifierFlag::COMMAND_R</autogen>
        </item>
    </root>
    
  7. Save the file

  8. Open in the menulet Karabiner -> Preferences the tab Change Key
  9. Hit the ReloadXML button
  10. Enable the remapping. It should be listed at the beginning.

If you want to use the right option/alt key instead of the left one just replace OPTION_L by OPTION_R and altL by altR everywhere in the private.xml file.

The above keycode customization is only valid for the en_US input source (and probably en_GB, en_CA etc).

If you use e.g the portuguese input source (pt_PT) then you have to choose the proper KeyCodes: to get the [ you have to press alt7. Then the line:

<autogen>__KeyOverlaidModifier__ KeyCode::OPTION_L, KeyCode::OPTION_L, KeyCode::BRACKET_LEFT, ModifierFlag::COMMAND_R

has to be changed to:

<autogen>__KeyOverlaidModifier__ KeyCode::OPTION_L, KeyCode::OPTION_L, KeyCode::KEY_7, ModifierFlag::OPTION_R | ModifierFlag::COMMAND_R

If you want to add a second custom keycode (hitting left cmd key once generates one forward command) use:

<?xml version="1.0"?>
<root>
    <item>
        <name>Option_L to Option_L</name>
        <appendix>(+ When you type Option_L only without other modifiers, send Command+[ in Safari)</appendix>
         <identifier>remap.altL2altL_backward_nomod</identifier>
         <only>SAFARI</only>
         <autogen>__KeyOverlaidModifier__ KeyCode::OPTION_L, KeyCode::OPTION_L, KeyCode::BRACKET_LEFT, ModifierFlag::COMMAND_R</autogen>
    </item>
    <item>
        <name>Command_L to Command_L</name>
        <appendix>(+ When you type Command_L only without other modifiers, send Command+] in Safari)</appendix>
        <identifier>remap.cmdL2cmdR_forward_nomod</identifier>
        <only>SAFARI</only>
        <autogen>__KeyOverlaidModifier__ KeyCode::COMMAND_L, KeyCode::VK_LAZY_COMMAND_L, KeyCode::BRACKET_RIGHT, ModifierFlag::COMMAND_R</autogen>
    </item>
</root>

The special KeyCode VK_LAZY_COMMAND_L instead of COMMAND_L doesn't break the function of cmd_left+Some_key: so you can navigate forward in Safari and print the page with cmd_leftP without going forward once more!

3
  • I did all like you said, it does not seem to work. I did quit/restart Safari though. If I want to enable "forward" with the command key, should I create a separate xml file?
    – pt109
    Commented Jan 18, 2016 at 22:43
  • @pt109 Hmm I tested in OS X Lion 10.7.5. First it was stubborn but then it worked for me. Which keyboard layout do you use? en_us? I will retry it in Mavericks! To add other keycodes you don't have to use a second xml Simply add it below </item> and </root>.
    – klanomath
    Commented Jan 18, 2016 at 22:48
  • I use el capitan 10.11.2 and a french azerty apple keyboard. I tried to activate an other, for example "change esc to caps lock", this one works!
    – pt109
    Commented Jan 19, 2016 at 7:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .