Help with zwift AHK script

I have checked the zwifthacks site and browsed, even tried some coding myself, but i can’t get this done so i’m asking for help here.

I want to use a wireless mouse to controll certain functions in zwift via keybindings, like pgup pgdn for ftp adjust in workouts, but i also want two other buttons on my mouse to function as media next and media previous.
I’ve tried using logitech software, but as soon as zwift is in focus this stops working.
The reason i’m doing this is that i’ve sacrificed an old gaming mouse and wired my discarded gen1 di2 shift buttons to the mouse (purely for indoor use), it’s janky but being able to press a button for certain functions lets me focus on pedaling rather than fiddeling with other prepherials.

I know AHK can do it, but i am not able to make it work.

Is there some genious here who could take a crack at it?
I only need to buttons to be able to send from the active zwift window to spotify, (minimized)
Without it actually bringing spotify to focus.

@Jesper_ZwiftHacks is the resident expert.

1 Like

I actually figured it out after about 4 hours in boiling my brains…
I can now control spotify and all zwift keyboard shortcuts from inside zwift with my old di2 buttons!
If anyone want the same functionality, then simply download Jespers media-button scrips and add
what function you want.

F21:: ; F21 is what i bound my button to in the logitech gaming software
DetectHiddenWindows, On
WinGet, winInfo, List, ahk_exe Spotify.exe
Loop, %winInfo%
thisID := winInfo%A_Index%
ControlFocus , , ahk_id %thisID%
ControlSend, , ^{right}, ahk_id %thisID%

This will cause the defined key to look for spotify and send it the [control]+[right] command for next song

List of more spotify controls are available on the internet.

Thank you for making these things so easy for the rest of us @Jesper_ZwiftHacks
And feel free to take my “contribution” and use it however you please if you want. :slight_smile:


Great that you figured it out!


Hello Jesper, after much hassle with my current “media button” an old mouse i configured in logitech to provide the correct inputs, i’ve bought the media button you linked in the article.
It’s working fine, but i can’t seem to get the play/pause button to bring up the action menu, and holding left just brings up a new tab in my browser for some reason instead of volume.
Do you have any idea what the reason might be?

It sounds like there is other keyboard related software (could be from Logitech) handling keyboard events and taking priority over your AHK script.

Check what you have running and try to disable it. You can also try to run the script as administrator to see if that makes a difference. This may also contain some hints: Frequently Asked Questions (FAQ) | AutoHotkey

Finally, you can see what the script actually detected as keypresses in its log. Right click the icon in the system tray and select ‘Open’. In the AHK window you can see the keypresses that were captured (View … Key history and script info).