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.


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).

Anyone else had trouble getting AutoHotkey to work with Zwift lately?

Second botched race now, trying to trigger powerup but ending up at the paired device screen instead, having to get off the bike and run over to the keyboard to press ESC. But then it’s all over, dropped hard mid race, downhill. :weary:

If they did something, then that might mean that my little BLE microcontroller project that I’m working on right now, a kind of replacement for the discontinued Zwift Kommander, won’t work for me either.

And it so happens that all of this coincides with the release of the Zwift PLAY controller… :triumph:

Wanna hide/hardcode keyboard shortcuts? Stupid, whatever. But affecting the HID interface like this is definitely out of bounds.

This is where someone (please!) steps in and says that their little gadget or off-brand game controller so and so still works fine.

(No, I can’t use companion app currently because it is so bad that it doesn’t reconnect properly and my wifi isn’t stable enough where I’m zwifting - app will drop sooner or later - and I’m not getting mesh or an extender for $300 just for that purpose.)

If spacebar still activate the PU then there would be no reason why AHK won’t work.

It could be that Zwift is running in administrator mode (elevated).

It is a simple thing to fix: Find the Zwift icon in the system tray in the Windows taskbar, right click it, and choose Exit. Next time you launch Zwift it will run in normal mode again.

1 Like

Good idea. Didn’t think of that. That would explain it. Too late now but I’ll try it and come back later.

I’m not stupid (just a little), mainly frustrated, I realize it wouldn’t be all that easy to block AHK. But that product release… it didn’t land well with me then, normally it would have.

Anyway, if I get it all sorted I’ll blog the schematics of the Poor Man’s PLAY somewhere in case someone would think it fun to build one themselves. Minimalistic, small, about half the sale price of the PLAY, although… you need to have written off the 3D printer first. I’ll be using a very small and easy to get rubber capped 5-way joystick. See if I can make a double click on the z-axis swap between 5 precoded hotkeys and a mouse mode, you know, for those last minute wheel changes. :smile: