Refresh Random after pressing a hotkey

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
MAZ12211
Posts: 2
Joined: 20 Mar 2023, 16:33
Contact:

Refresh Random after pressing a hotkey

Post by MAZ12211 » 25 Mar 2023, 12:36

The only way for me to refresh randomTrack is via restarting the ahk file
But I want it to refresh after pressing CTRL + 3 for example
I tried refreshing it via loading up the ahk file after a hotkey but that didn't work...

Code: Select all

#SingleInstance Force
randomTrack := Random(1, 2)
isMuted := false
MsgBox "Controls:`nCTRL + 2 | Opens up the terminal`nCTRL + 3 | Loads a random song/track in tracks folder`nCTRL + 4 | Switchs to a mute song track"
^2::
{
    Run "wt.exe"
}

^3::
{
    SoundPlay "F:\Games\MAZ folder\Entries\tracks\track-" . randomTrack . ".mp3"
    ;loads track-1 or track-2 depending on randomTrack
}
^4::
{
    isMuted := True
    if isMuted = true {
        SoundPlay "F:\Games\MAZ folder\Entries\tracks\mute track.mp3"
    }
}

User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: Refresh Random after pressing a hotkey

Post by mikeyww » 25 Mar 2023, 15:58

Hello,

The Random function can be called inside your hotkey subroutine. This would mean that a new random number is generated whenever the hotkey is triggered.

Post Reply

Return to “Ask for Help (v2)”