AutoHotkey Focus Macro

If you haven't heard of AutoHotkey then first I would recommend you go and check it out.  Basically its a simple macro programming language that allows you to create keyboard and mouse shortcuts.

Free keyboard macro program. Supports hotkeys for keyboard, mouse, and joystick. Can expand abbreviations as you type them (AutoText).

For example, you might want to have Notepad start when you press the Windows Logo key and N.  Or maybe Microsoft Word open when you press Windows key and W. The possibilities are endless, and you can program a large number of key combinations, mouse buttons and other events in a pretty simple language.  You are not limited to just simple actions, you can move things around the screen, open and close apps, hide and show windows, click things, cut and paste text, display custom dialogs, and much more.

If you don't want to have a go at it yourself, there are loads of forums out there with working examples that you can simply cut and paste into your own local macro file. Just have a look at the AutoHotkey boards.

AutoHotkey Community - Index page

Here is an example I wrote that allows you to use the middle mouse button to bring the window under the mouse into focus on your main display and maximize the window.  Once on the main window, if you click the middle button again on the window, the window will return to its original position.  Obviously multiple monitors are really needed to make the most out of this!

; Max Window to Primary / Restore
; for multi-monitor setups on Windows 10
; Steve Pilkington, Italik, 2022
MouseGetPos, , , hwnd_id
WinGetPos, curr_x, curr_y, , , ahk_id %hwnd_id%
If (curr_x = -8 and curr_y = -8) {
    If (orig_minmax_state = 0) 
        WinRestore, ahk_id %hwnd_id%
    WinMove, ahk_id %hwnd_id%, , %orig_x%, %orig_y%
    WinActivate, ahk_id %hwnd_id%
} else {
    WinGet, orig_minmax_state, MinMax, ahk_id %hwnd_id%
    WinGetPos, orig_x, orig_y, , , ahk_id %hwnd_id%
    WinMove, ahk_id %hwnd_id%, , -8,-8
    WinMaximize, ahk_id %hwnd_id%WinActivate, ahk_id %hwnd_id%

I have only really tested this on Windows 10 but seems to work pretty reliably. Feel free to add it to your own macros and improve it where you can.