Set up a Mouse for Productivity with AutoHotkey

See how I set up my multi-button mouse for productivity. Gamer mice are known to have some extra buttons here and there. Their software allows you to map the keys to some actions. I’ve been improving upon that idea for the past ten years or so, thereby allowing me to present a very geeky but time-saving solution. This setup is not a quick tip per se, but hopefully, you’ll be able to integrate this into your daily life. My mouse is a Logitech (get $5 off!) G700s, but the method applies to any input device with programmable buttons.

A reason why

Does this have anything to do with WordPress? Have you ever seen this?

High revision count in WordPress

On this exaggerated example, the high revision count shows a lot of fiddling. So much that somebody hit Update, switched a tab in the browser, reloaded the page, observed the change, then went back to the edit screen. 136 times! We do this all the time, even with front-end live preview builders such as Elementor. When writing an article or designing a layout, us perfectionists have this twitch to check the front-end result continually. All these minor subtasks take a lot of time in the long run. What if I told you that this barely needs any mouse movement?

How I set up my mouse for productivity

With the help of AutoHotkey (Windows) and some scripting, I’ve taken programming a mouse for productivity to a whole new level. My mouse is currently capable of these tasks:

  • Double click
  • Previous tab
  • Next tab
  • Reload tab
  • Close tab
  • Undo closed tab
  • Back
  • Inspect element (open developer tools)

And that’s just in the browser. A button can do another action in each different software. The double-click button is my personal favorite.

I can’t remember the last time I double-clicked.

As soon as I got my first mouse with a thumb button, I managed to delegate the act of double-clicking to the thumb button.

Official software setup

I began by using the software (driver) that came with the mouse. These are getting better and better nowadays, but they might be slow to detect window changes. They limit what you can do, and the setup may not be that portable between computers. Install the free AutoHotkey, a macro software I use to (re)direct button actions on a per-application basis.

There are keys called F1F12 on most keyboards. Interestingly, it’s little known that virtual F13F24 keys exist too. I assign each extra mouse button one of these function keys. Then an AutoHotkey script translates the input to my desired action.

Upon assigning, the mouse software awaits your keypress: “enter your keystroke”. Yes, but how do we assign F13F24 keys if we can’t press them? AutoHotkey comes to the rescue as it can simulate any keypress. It’s straightforward: save the following snippet as a file called send.ahk.

Sleep, 5000
Send {F15}
ExitApp

Upon running, it waits 5 seconds to press F15 for you. Continue doing this for all the buttons you want to reconfigure. Multiply the first two lines, and change F15 in them to something else. By default, these virtual function keys don’t do anything. They only wait to be assigned a real action by AutoHotkey! Now you have a seemingly dumb mouse where the extra buttons fire virtual function keys to the system.

I set up my Logitech g700s mouse for productivity

Scripting the mouse for productivity with AutoHotkey

Now it gets interesting. AutoHotkey is impressive, and I use it for many things to automate and macro tasks. I’ll show you how to customize buttons for two applications and create fallback button assignments.

Establishing the AutoHotkey script file

To run it automatically on Windows start:

  1. Create a new text file with the extension .ahk and save it.
  2. Press Windows+R and run this shell:startup
  3. Hold down Alt and drag the file into that Startup folder to create a shortcut

Start adding the snippets from here to the file, one after the other (whichever you’d like to use). The following is mandatory and it ensures proper operation for the script. Hint: if you open the .ahk file with Sublime Text it’ll do syntax highlighting for you.

; Recommended for all new scripts
#NoEnv 
; Makes Send synonymous with SendInput or SendPlay instead of SendEvent
SendMode Input 
; Ensures a consistent starting directory
SetWorkingDir %A_ScriptDir% 
; A window's title can contain WinTitle anywhere inside it to be a match
SetTitleMatchMode 2 
; Specifies the rate of hotkey activations
#MaxHotkeysPerInterval 300
; Forces the unconditional installation of the mouse hook
#InstallMouseHook 

Moving forward with the application-specific code, you shouldn’t blindly copy paste everything to this file. Your mouse might not offer this many buttons. Thus you need to cross reference the actual bindings you used in the mouse software. Programming a mouse for productivity is a personalized task, so take the time to configure it the way you want it.

Targeting the Chrome browser

Using the following snippet will carry out the tasks mentioned above.

; Chrome browser
#If WinActive("ahk_exe chrome.exe")
    ; Ctrl+w = Close tab
    F14::Send ^w
    ; Ctrl+C where C is uppercase, so Ctrl+Shift+C
    ; Open developer tools and inspect the element under the mouse
    F22::^C
    ; Ctrl+PageDown = Next tab
    F16::Send ^{PgDn}
    ; Ctrl+PageUp = Previous tab
    F17::Send ^{PgUp}
    ; Alt+Left = Back in history
    F18::Send !{Left}
    ; F5 = Reload tab
    F20::F5
    ; Ctrl+T where T is uppercase, so Ctrl+Shift+T = Reopen closed tab
    F23::Send ^T
#IfWinActive

Targeting Photoshop: remapping a Wacom pen & tablet

Let’s take a look at another productive use with a little bit more complex actions. Instead of switching browser tabs with my thumb buttons, those now have an undo/redo action. As an example, I like drawing with my Wacom tablet, and I ported this approach to function keys of the tablet.

Wacom Bamboo MTE-450

There are keys on the side of the pen too, and AutoHotkey helps me remap one of these to access the color picker. When I let go of holding it, I get the brush back, ready to paint with the new color. The mapping is equivalent to holding down Alt.

Furthermore, the other button is responsible for dragging the document around – it’s the same as holding the Space bar. When I push the scroll wheel to the right, in sort of a casual “exit to the right” movement, I get the “Save for Web” dialog I often use. Not only is it very convenient, but I also don’t have to memorize shortcuts or dig deep into the menu.

; Photoshop
#If WinActive("ahk_exe photoshop.exe")
    ; Hold down Alt key for using the color picker
    F14::
        if GetKeyState("Alt")
            return  
        Send {Alt down}
        return
    ; Release the Alt key
    F14 Up::Send {Alt up}
    ; Alt+Ctrl+z = Step backward (similar to undo) 
    F16::Send {LAlt down}{LControl down}z{LControl up}{LAlt up}
    ; Shift+Ctrl+z = Step forward (similar to redo) 
    F17::Send {LShift down}{LControl down}z{LControl up}{LShift up}
    ; Hold down Space to move a zoomed document around
    F18:: 
        if GetKeyState("Space")
            return  
        Send {Space down}
        Send {Click down}
        return
    ; Release the Space
    F18 Up:: 
        Send {Space up}
        Send {Click up}
        return
    ; Ctrl+s = Save
    F19::^s
    ; Ctrl+n = New...
    F20::^n
    ; Alt+Shift+Ctrl+s = File -> Export -> Save for Web 
    F23::^!S
#IfWinActive

Default fallback – general actions for the OS

I needed default bindings when no particular software is detected. Consequently, I define the ubiquitous double click, among a boss button.

; Base setup of keys!
; General purpose back button
F14::Backspace
; Double click!
F15::Send {Click 2}
; Redundant middle mouse button (easier to press than the tiltable scroll wheel)
F19::MButton
; Windows+d = Minimize all windows and show the desktop
F21::#d

How to target other specific software with AutoHotkey?

You might notice the "ahk_exe chrome.exe" or "ahk_exe photoshop.exe" in the above snippets. They are just the file names of the executables that create their windows. As a result, the WinActive function has something to work with. If you are unsure:

  1. Right click on the tray icon of AutoHotkey
  2. Choose Window Spy
  3. Click the target window
  4. Read all the info you need, such as Window Title, Class and Process

This process allows you to bind any action to any mouse button, on a per-application basis. Use this in many ways, not limited to:

  • Quickly access tools in Photoshop
  • Add shortcuts of your photo viewer to the mouse
  • Control your (HTPC) video player with just the mouse
  • Send pre-written text macros when providing support
  • Move game keybindings to the mouse
  • Switch between conversations in Skype
  • Test poorly written UI code by holding down the double click button and see what happens (it repeats clicks very fast)
  • Don’t just set up a mouse for productivity, try your other input devices for various purposes. These include drawing pen & tablets, joysticks, etc. Even 3Dconnexion mice for CGI artists (also founded by Logitech).

Bonus: Allocate buttons to global hotkeys to control music (Spotify)

Here is another one, this controls Spotify. I don’t need global control of it as I have multimedia keys on the keyboard. If you don’t have them, then this snippet will be of some help. However, actions starting with Media_ and Volume_ are global and don’t require detecting Spotify.exe to work.

#If WinActive("ahk_exe Spotify.exe")
    ; Seek backwards: Shift+Left
    F16::Send +{Left}
    ; Seek foward Shift+Right
    F17::Send +{Right}
    ; Previous song
    F18::Send {Media_Prev}
    ; Play or pause
    F19::Send {Media_Play_Pause}
    ; Next song
    F20::Send {Media_Next}
    ; Volume down
    F22::Send {Volume_Down}
    ; Mute
    F14::Send {Volume_Mute}
    ; Volume up
    F23::Send {Volume_Up}
#IfWinActive

Conclusion

To sum up, this is what we did to tune a mouse for productivity:

  1. Get a multi-button (gamer?) mouse
  2. Teach its software to bind extra buttons to F13F24 keys
  3. Remap those keys globally or on a per-application basis with AutoHotkey

I see many – otherwise productive – people not using any mouse at all. For me this is unfathomable, but I understand that compactness of using just the touchpad can be a benefit. However, I can’t operate that way, and even a simple mouse is not enough. In turn, this setup makes me look like a wizard who seemingly controls software with his thoughts. After all, the keys and their functions are in my muscle memory. I don’t even consciously think about what to press.

Actions happen so fast, it gives onlookers that “What the hell is happening on your screens?” stare. Just the way I like it.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Join Our Newsletter!

Get secret tips and valuable details about making your site more successful.

Follow Us!

We Recommend

This site is powered by Elementor

100% Free  WP Website Builder  All-in-One Solution

Monthly Archives

Scroll Up