如何将 space 添加到格式

How to add space to formatting

我是编码新手,发现了一个将歌曲和艺术家写入名为 PlayLog.txt 的 txt 文件的脚本。当我使用脚本时,它按预期工作,但是我不知道如何将 space 添加到输出的末尾。

所以我想要“[艺术家]的[歌曲] + 8 spaces”而不是“[艺术家]的[歌曲]” 这样我的 OBS 中的滚动文本就不会将艺术家的结尾与歌曲的开头合并。

; This script displays the currently playing song from the pandora one app
; 
; Any future updates can be found at http://notunusual.net/pandoraone_autohotkey/
;
; This function relies heavily on the excellent tray icon script by Sean, the original version
; of these functions can be found here - http://www.autohotkey.com/forum/topic17314.html
;
; Updates to the tray icon functions originally by Fanatic Guru, as per the following link:
; http://www.autohotkey.com/board/topic/94573-autohotkey-startup-consolidate-ahk-scripts-tray-icons/?p=595938
;
; Further updates to the tray icon functions and to this script in general by RiseUp.


; Make the script work even if the window is hidden
DetectHiddenWindows, on

; Only allow a single instance of the script
#SingleInstance

LogFileDir := A_AppData . "\notunusual\PandoraOne\"
LogFile := LogFileDir . "PlayLog.txt"

FileCreateDir, %LogFileDir%

if (ErrorLevel = 1)
{
    MsgBox "Error creating directory!"
}

prevArtist := ""
prevSong := ""
while (true)
{
   GetCurrentPlayingSong(curSong, curArtist)
   if (((curSong <> prevSong) or (curArtist <> prevArtist)) and ((curSong <> "") and (curArtist <> "")))
   {
        prevSong := curSong
        prevArtist := curArtist
        FileDelete, %LogFile%
        if ErrorLevel
            MsgBox, Error deleting PlayLog.txt!
        FileAppend %prevSong% by %prevArtist%, %LogFile%
   }

   ; This is how often a check will be done, a sleep of 1000 means every 1 second we'll check the value
   Sleep, 1000
}

; This returns the current song in the format Song by Artist, this can easily be changed to
; whatever format is desired
GetCurrentPlayingSong(ByRef songName, ByRef artist, space)
{
    TI := TrayIconsSearch("Pandora.exe")
    StringSplit,TIV, TI, |
    toolTip := RegExReplace(TIV9, "Tooltip: ")

    StringSplit, toolTipArray, toolTip, `n
    songName := toolTipArray2
    artist := RegExReplace( toolTipArray3, "by " )

}


TrayIconsSearch(sTerm)
{
    Tray_Icons := {}
    Tray_Icons := TrayIcons(sTerm)

    if A_OSVersion in WIN_VISTA,WIN_7,WIN_8
    {
        arr := {}
        arr := TrayIconsOverflow(sTerm)
        for index, element in arr
            Tray_Icons.Insert(element)
        arr := ""
    }

    for index, element in Tray_Icons
        sTrayIcons .= "idx: " . element.idx . " | idn: " . element.idn . " | Pid: " . element.pid . " | uID: " . element.uID . " | MessageID: " . element.MessageID . " | hWnd: " . element.hWnd . " | Class: " . element.Class . " | Process: " . element.Process . "`n" . "   | Tooltip: " . element.Tooltip . "`n`n"
    Return sTrayIcons
}


TrayIcons(sExeName = "")
{
    arr := {}
    Setting_A_DetectHiddenWindows := A_DetectHiddenWindows
    DetectHiddenWindows, On
    WinGet, pidTaskbar, PID, ahk_class Shell_TrayWnd
    hProc:= DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
    pProc:= DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 32, "Uint", 0x1000, "Uint", 0x4)
    idxTB:= GetTrayBar()

    SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_BUTTONCOUNT
    Loop,   %ErrorLevel%
    {
        SendMessage, 0x417, A_Index-1, pProc, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_GETBUTTON
        VarSetCapacity(btn,32,0), VarSetCapacity(nfo,32,0)
        DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pProc, "Uint", &btn, "Uint", 32, "Uint", 0)
            iBitmap := NumGet(btn, 0)
            idn := NumGet(btn, 4)
            Statyle := NumGet(btn, 8)
            If  dwData  := NumGet(btn,12,"Uint")
                iString := NumGet(btn,16)
            Else    dwData  := NumGet(btn,16,"int64"), iString:=NumGet(btn,24,"int64")
        DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "Uint", &nfo, "Uint", 32, "Uint", 0)
        If  NumGet(btn,12,"Uint")
            hWnd    := NumGet(nfo, 0)
        ,   uID := NumGet(nfo, 4)
        ,   nMsg    := NumGet(nfo, 8)
        ,   hIcon   := NumGet(nfo,20)
        Else    hWnd    := NumGet(nfo, 0,"int64"), uID:=NumGet(nfo, 8,"Uint"), nMsg:=NumGet(nfo,12,"Uint")
        WinGet, pid, PID,              ahk_id %hWnd%
        WinGet, sProcess, ProcessName, ahk_id %hWnd%
        WinGetClass, sClass,           ahk_id %hWnd%
        If !sExeName || (sExeName = sProcess) || (sExeName = pid)
            VarSetCapacity(sTooltip,128), VarSetCapacity(wTooltip,128*2)
        ,   DllCall("ReadProcessMemory", "Uint", hProc, "Uint", iString, "Uint", &wTooltip, "Uint", 128*2, "Uint", 0)
        ,   DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wTooltip, "int", -1, "str", sTooltip, "int", 128, "Uint", 0, "Uint", 0)
        ,   Index = arr.MaxIndex()>0 ? arr.MaxIndex()+1 : 1
        ,   arr[Index,"idx"] := A_Index-1
        ,   arr[Index,"idn"] := idn
        ,   arr[Index,"Pid"] := Pid
        ,   arr[Index,"uID"] := uID
        ,   arr[Index,"MessageID"] := nMsg
        ,   arr[Index,"hWnd"] := hWnd
        ,   arr[Index,"Class"] := sClass
        ,   arr[Index,"Process"] := sProcess
        ,   arr[Index,"Tooltip"] := (A_IsUnicode ? wTooltip : sTooltip)
    }
    DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pProc, "Uint", 0, "Uint", 0x8000)
    DllCall("CloseHandle", "Uint", hProc)
    DetectHiddenWindows, %Setting_A_DetectHiddenWindows%
    Return  arr
}

TrayIconsOverflow(sExeName = "")
{
    arr := {}
    Setting_A_DetectHiddenWindows := A_DetectHiddenWindows
    DetectHiddenWindows, On
    WinGet, pidTaskbar, PID, ahk_class NotifyIconOverflowWindow
    hProc:= DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
    pProc:= DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 32, "Uint", 0x1000, "Uint", 0x4)
    idxTB:= 1
        SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class NotifyIconOverflowWindow   ; TB_BUTTONCOUNT
    Loop,   %ErrorLevel%
    {
        SendMessage, 0x417, A_Index-1, pProc, ToolbarWindow32%idxTB%, ahk_class NotifyIconOverflowWindow   ; TB_GETBUTTON
        VarSetCapacity(btn,32,0), VarSetCapacity(nfo,32,0)
        DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pProc, "Uint", &btn, "Uint", 32, "Uint", 0)
            iBitmap := NumGet(btn, 0)
            idn := NumGet(btn, 4)
            Statyle := NumGet(btn, 8)
        If  dwData  := NumGet(btn,12,"Uint")
            iString := NumGet(btn,16)
        Else    dwData  := NumGet(btn,16,"int64"), iString:=NumGet(btn,24,"int64")
        DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "Uint", &nfo, "Uint", 32, "Uint", 0)
        If  NumGet(btn,12,"Uint")
            hWnd    := NumGet(nfo, 0)
        ,   uID := NumGet(nfo, 4)
        ,   nMsg    := NumGet(nfo, 8)
        ,   hIcon   := NumGet(nfo,20)
        Else    hWnd    := NumGet(nfo, 0,"int64"), uID:=NumGet(nfo, 8,"Uint"), nMsg:=NumGet(nfo,12,"Uint")
        WinGet, pid, PID,              ahk_id %hWnd%
        WinGet, sProcess, ProcessName, ahk_id %hWnd%
        WinGetClass, sClass,           ahk_id %hWnd%
        If !sExeName || (sExeName = sProcess) || (sExeName = pid)
            VarSetCapacity(sTooltip,128), VarSetCapacity(wTooltip,128*2)
        ,   DllCall("ReadProcessMemory", "Uint", hProc, "Uint", iString, "Uint", &wTooltip, "Uint", 128*2, "Uint", 0)
        ,   DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wTooltip, "int", -1, "str", sTooltip, "int", 128, "Uint", 0, "Uint", 0)
        ,   Index = arr.MaxIndex()>0 ? arr.MaxIndex()+1 : 1
        ,   arr[Index,"idx"] := A_Index-1
        ,   arr[Index,"idn"] := idn
        ,   arr[Index,"Pid"] := Pid
        ,   arr[Index,"uID"] := uID
        ,   arr[Index,"MessageID"] := nMsg
        ,   arr[Index,"hWnd"] := hWnd
        ,   arr[Index,"Class"] := sClass
        ,   arr[Index,"Process"] := sProcess
        ,   arr[Index,"Tooltip"] := (A_IsUnicode ? wTooltip : sTooltip)
    }
    DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pProc, "Uint", 0, "Uint", 0x8000)
    DllCall("CloseHandle", "Uint", hProc)
    DetectHiddenWindows, %Setting_A_DetectHiddenWindows%
    Return  arr
}


GetTrayBar()
{
    ControlGet, hParent, hWnd,, TrayNotifyWnd1  , ahk_class Shell_TrayWnd
    ControlGet, hChild , hWnd,, ToolbarWindow321, ahk_id %hParent%
    Loop
    {
        ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
        If  Not hWnd
            Break
        Else If hWnd = %hChild%
        {
            idxTB := A_Index
            Break
        }
    }
    Return  idxTB
}

嗯……我咬。这是您需要修改的代码。

FileAppend %prevSong% by %prevArtist%, %LogFile% 

下面是我将如何修改它。

NewVar := prevSong . " by " . prevArtist . "        "
FileAppend %NewVar%, %LogFile%

仅供参考,代码本身有此方法的示例,如果您研究一下就会看到它。