How to remap your mouse keys using karabiner on macOS

  • Button 4 to go backwards in Safari
  • Button 5 to go forward in Safari
  • Button 3 to close the current tab in Safari

Karabiner Event Viewer

Before we start with the code I want to talk a little bit about the Karabiner Event Viewer. This tool helped me a lot because it allowed me to understand Firefox’s Bundle Identifier (we’ll see later why I needed this information) and it also allowed me to debug the configuration.
You can open the Event Viewer from the Karabiner’s icon that you should have in the status bar.

Let’s write the configuration file

Into the karabiner.json file, we have to add some pieces of information in the “complex_modifications” field.

  • First of all, I wanted to use the “button4” to go back to the previous page in Safari. After I wrote this rule I discovered that it also works in the Finder but it does not work in Firefox because Firefox does not support this shortcut (I wrote a different rule for it).
    In this rule I had to add a condition, the rule works only if the frontmost application is different than Firefox.
    In this case when I press the “button4” I simulate the shortcut CMD+[+ALT that is used in Safari to go to the previously visited page.
    The go Forward shortcut is similar to the previous one, in this case, I remap the “button5” to run the shortcut CMD+]+ALT.
  • As I said Firefox has a different shortcut to go backward to the previously visited page so I had to write a different rule.
    In this case, in the condition, I use the type “frontmost_application_if” because I want to execute the shortcut if and only if Firefox is the frontmost application. In this case, I remap the “button5” to the shortcut CMD+left arrow.
  • The last rule I want to talk about is the one that I wrote to close the current tab. In this case, when I press the “button3” I want to execute the shortcut CMD+W.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Computer Science student 🎓👨🏻‍💻🎧