如何使用自动热键播放我喜欢的歌曲

问题描述 投票:0回答:1

我用了这个代码

^+!l::
SetTitleMatchMode, 2
IfWinExist, Spotify
{
    WinActivate
    Send, ^l
}
else
{
    Run, "C:\Users\YourUsername\AppData\Roaming\Spotify\Spotify.exe"
    WinWait, Spotify
    WinActivate
    Send, ^l
}
return

但我不断收到错误,例如此代码包含语法错误函数调用需要空格或(仅在参数之间使用逗号

我尝试使用聊天 gpt 解决问题,但我在 v2 上不断遇到错误

autohotkey
1个回答
0
投票
#Requires AutoHotkey v2.0

^+!l::
{
    if WinExist("ahk_exe Spotify.exe")
    {
        WinActivate
        if WinWaitActive("ahk_exe Spotify.exe", , 2)
            Send "^l"
    }
    else
    {
        Run "C:\Users\YourUsername\AppData\Roaming\Spotify\Spotify.exe"
        if WinWait("ahk_exe Spotify.exe", , 5)
        {
            WinActivate
            if WinWaitActive("ahk_exe Spotify.exe", , 5)
            {   
                Sleep 2000
                Send "^l"
            }
        }
    }
}

要熟悉 AutoHotkey,请阅读初学者教程

© www.soinside.com 2019 - 2024. All rights reserved.