#include <WinAPIProc.au3>
#include <WinAPISys.au3>
Local $hWnd, $ahWnd, $hControl, $hToolbar, $aText[2], $aTitles, $sClip
Local $sFlacFile = '1.flac', $aProcessList = ProcessList('Notepad.exe')
Local $iPID = $aProcessList[$aProcessList[0][0]][1]
If Not $iPID Then Exit 1 ; MsgBox(262144 + 16, Default, 1)
$ahWnd = _WinAPI_EnumProcessWindows($iPID) ; Вычисляем окно последнего запущенного процесса
If @error Then Exit 2 ; MsgBox(262144 + 16, Default, 2)
$hWnd = WinActivate($ahWnd[$ahWnd[0][0]][0])
If (Not $hWnd) Then Exit 3 ; MsgBox(262144 + 16, Default, 3)
_FixAccelHotKeyLayout()
$sClip = ClipGet()
$aText[0] = StringStripWS($sClip, 3) ; Пункт 1) - Берем текст из буфера на прямую, без вставки в поле блокнота
_WunSend('{CTRLDOWN}ax{CTRLUP}', $hWnd) ; Ctrl+a, Ctrl+x
$aText[1] = ClipGet()
If (Not $aText[0]) Or (Not $aText[1]) Then Exit 4 ; MsgBox(262144 + 16, Default, 4)
$aText[0] = StringRegExpReplace($aText[0], '(?i)(FILE\h*")[^"]+("\h*WAVE)', '${1}' & $sFlacFile & '$2') ; Пункт 2) замена текста CDImage.wav на 1.flac
$aTitles = StringRegExp($aText[1], '[\R\s]*(.+)', 3)
If @error Then Exit 5 ; MsgBox(262144 + 16, Default, 'Ошибка №5' & @CRLF & '$aText[1]:' & @CRLF & '[' & $aText[1] & ']')
For $i = 0 To UBound($aTitles) - 1 ; Пункт 3) и 4)
$aText[0] = StringRegExpReplace($aText[0], '(?i)(AUDIO)(\s+INDEX)', '$1' & @CRLF & ' TITLE "' & $aTitles[$i] & '"$2', 1)
Next
ClipPut($aText[0])
_WunSend('{CTRLDOWN}vs{CTRLUP}', $hWnd) ; Ctrl+v, Ctrl+s
WinKill($hWnd) ; Закрыть окно
ClipPut($sClip)
Func _FixAccelHotKeyLayout()
Static $iKbrdLayout, $aKbrdLayouts
If Execute('@exitMethod') <> '' Then
Local $iUnLoad = 1
For $i = 1 To $aKbrdLayouts[0]
If Hex($iKbrdLayout) = Hex('0x' & StringRight($aKbrdLayouts[$i], 4)) Then
$iUnLoad = 0
ExitLoop
EndIf
Next
If $iUnLoad Then
_WinAPI_UnloadKeyboardLayout($iKbrdLayout)
EndIf
Return
EndIf
$iKbrdLayout = 0x0409
$aKbrdLayouts = _WinAPI_GetKeyboardLayoutList()
_WinAPI_LoadKeyboardLayout($iKbrdLayout, $KLF_ACTIVATE)
OnAutoItExitRegister('_FixAccelHotKeyLayout')
EndFunc ;==>_FixAccelHotKeyLayout
Func _WunSend($sLetter, $hWnd)
SendKeepActive($hWnd)
Send($sLetter)
SendKeepActive('')
EndFunc ;==>_Send