AHK Hotkey在字符串中的表达式,命令之间没有空格

AHK Hotkey's expression in string, separate commands without spaces

好的,我有这部分代码:

SetGrenade:
    gui, 2: Submit, NoHide
    if Flashbang 
        CurrentNade := "send 4|Sleep 20|send 4|Sleep 1000|Send {LButton}|Sleep 100|send 1"
    else if Smoke 
        CurrentNade := "Send 4|Sleep 20|Send 4|Sleep 20|Send 4|Sleep 1000|Send {LButton}|Sleep 100|Send 1"
    else ;He
        CurrentNade := "send 4|Sleep 1000|Send {LButton}|Sleep 100|Send 1"
return

(这个的热键是 xbutton1) 一切正常,除了这个 '|'竖线用于分隔命令,但它也放置了 space。例如: 用户在单击鼠标上的 xbutton1 时选择选项 1 (Flashbang),他会得到以下信息: 4 4 1 不是 441(我跳过了睡眠和点击,因为它们没有显示在记事本中。)

有办法解决这个问题吗? 我尝试删除竖线 (|),但随后代码被放置为文本。 请帮忙, 问候, 亚当

编辑: 完整代码:

#SingleInstance force
SetWorkingDir %A_ScriptDir%
CurrentNade := 0
;GUI
Gui, Show, w200 h300, sAHK v0.2
Gui, Add, checkbox, gAutoNade vAutoNade cBlue, Enable Auto-Grenade
Gui, Add, button, vSettingsButton gSettings, View Settings
Gui, Add, button, gUpcoming, View Upcoming Functions

Hotkey, xbutton1, CurrentNade, Off

Gui, 2:Hide
Gui, 2:Add, Text, cBlue, Auto-Grenade To Throw:
Gui, 2:Add, radio, gSetGrenade vFlashbang, Flashbang
Gui, 2:Add, radio, gSetGrenade vSmoke, Smoke Grenade
Gui, 2:Add, radio, gSetGrenade vHe, Explosive Grenade

OnExit, GuiClose

return

;END GUI

;EXPRESSION

Settings:
WinGetPos, guiPosX, guiPosY,,, A
guiPosX := guiPosX + 200
Gui, 2:Show, x%guiPosX% y%guiPosY% Restore
Gui, 2:Show, w200 h300, Script Settings
return

AutoNade:
    gui, Submit, NoHide
    if AutoNade
    {
        SoundPlay, %A_ScriptDir%/snd-EN/SL.wav
    Hotkey, xbutton1, On
    }
    else
    {
    Hotkey, xbutton1, Off
    SoundPlay, %A_ScriptDir%/snd-EN/ST.wav
    }   
return

CurrentNade:
    ;MsgBox %CurrentNade%
    Loop, Parse, CurrentNade,|
    {
    if instr(A_LoopField,"send")
        send % SubStr(A_LoopField, 5)
    else
        Sleep SubStr(A_LoopField, 6)
    }
return

SetGrenade:
    gui, 2: Submit, NoHide
    if Flashbang 
        CurrentNade := "send 4|Sleep 20|send 4|Sleep 1000|Send {LButton}|Sleep 100|send 1"
    else if Smoke 
        CurrentNade := "Send 4|Sleep 20|Send 4|Sleep 20|Send 4|Sleep 1000|Send {LButton}|Sleep 100|Send 1"
    else ;He
        CurrentNade := "send 4|Sleep 1000|Send {LButton}|Sleep 100|Send 1"
return

Upcoming:
Gui, Upcoming:Add, Text,, 1. Overall impovements, UI updates, bug fixes and small changes
Gui, Upcoming:Add, Text,, 2. Bunny Hop
Gui, Upcoming:Add, Text,, 3. 180 turnaround
Gui, Upcoming:Add, Text,, 4. Recoil Reducer (RCS)
Gui, Upcoming:Show
return

GuiClose:
ExitApp

;END EXPRESSION
AutoHotKey 中的

substr 根据 documentation:

基于 1

For StartingPos, specify 1 to start at the first character

只需将代码中的索引增加 1:

if instr(A_LoopField,"send")
    send % SubStr(A_LoopField, 6)
else
    sleep SubStr(A_LoopField, 7)
}