Jump to content

VLC Mover -- moves VLC to different monitor when playing certain files


Bilgus
 Share

Recommended Posts

I made this application at the behest of another user because it sounded like a really cool idea.

I've been using it for a little over 7 months and I really like it.

 

After Compiling:

If you want to use it as a pass through you'll need to name the script Vlc.exe and the original vlc.exe to Vlc_Orig.exe.

On first run it will create a settings.ini with default settings and pop up the settings dialog

Running VLC.exe again only runs the script passes on the new commandline and exits the script

the previous script stays running...

Once you close the VLC window after a few seconds a pop up will appear F1- Help, F4 - settings, ESC - Quit without saving

DEFAULTS TO:
[Config]
CloseOnInactive=0
MaximizeOnActivate=0
IgnoreFilesLessThanMB=0
KeyDelayMS=100
KeyDownDelayMS=50
ExecName=VLC_Orig.exe
ActiveWindowCoords=0
InactiveWindowCoords=0
ExecOnActive=
ExecOnInactive=
KeysOnActivate=f
KeysOnInactive=
FileTypes=mp4,avi,mkv,wmv
WindowName=VLC media player
WindowTextFallback=VLC (Direct3D output)
;------------------------------------------------
[Config]
CloseOnInactive=0 ;1 - Closes the vlc_orig.exe when the video ends
MaximizeOnActivate=0 ;1 - Maximizes window when video is detected
IgnoreFilesLessThanMB=0 ;0-1000x?? - Passthrough Ignores files less than this
KeyDelayMS=100
KeyDownDelayMS=50
Exec_Name=VLC_Orig.exe
ActiveWindowCoords=0 ;- moves window to this position on video stop 0 ignores or format 0,0,1000,1000 => x,y,w,h
InactiveWindowCoords=0 ;- moves window to this position on video stop 0 ignores or format 0,0,1000,1000 => x,y,w,h
ExecOnActive= ;execute this file when video is detected
ExecOnInactive= ;execute this file when when video stops
KeysOnActivate=f ;-keys to press when video is detected
KeysOnInactive= ;-keys to press when video stops
FileTypes=mp4,avi,mkv,wmv ;-Comma separated list of valid video files
WindowName=VLC media player ;
WindowText_Fallback=VLC (Direct3D output) ;if valid ext not found fallback to looking for windowname and this text

 

If you don't want to use it as a pass through you'll probably need to change it a bit to do what you want

 

VlcMover.ico

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
;;#AutoIt3Wrapper_Icon=VlcMover.ico
#AutoIt3Wrapper_Outfile=VLC86.exe
#AutoIt3Wrapper_Outfile_x64=VLC64.exe
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****


Global $gsINI_PATH = @AppDataDir & "\" & @ScriptName & "_PassThrough.ini" ;Needs to be in @AppDataDir to have write access
Global Const $gsINI_SEC = "Config"
If FileExists(@ScriptDir & "\" & @ScriptName & "_PassThrough.ini") Then
    $gsINI_PATH = @ScriptDir & "\" & @ScriptName & "_PassThrough.ini"
EndIf ;Override with ini file in script directory, probably not writeable though

;------------------------------------------------------------------------------------
;GUIConstantsEx
Global Const $GUI_EVENT_CLOSE = -0x3

Global Const $giACTWAIT = 5 ;wait #seconds for window to become active

Global Enum $ge_bClose = 0, $ge_bMaximize, $ge_iMinSize, $ge_iKeyDelay, $ge_iKeyDnDelay, $ge_sExecute, _
        $ge_sActCoord, $ge_sInACoord, $ge_sActExec, $ge_sInAExec, $ge_sSendKeysAct, $ge_sSendKeysInA, _
        $ge_sFileTypes, $ge_sWndName, $ge_sWndFbTxt, $ge_LASTCFG

Global Const $gaIniKeys[$ge_LASTCFG] = ["CloseOnInactive", "MaximizeOnActivate", "IgnoreFilesLessThanMB", "KeyDelayMS", _
        "KeyDownDelayMS", "ExecName", "ActiveWindowCoords", "InactiveWindowCoords", "ExecOnActive", "ExecOnInactive", _
        "KeysOnActivate", "KeysOnInactive", "FileTypes", "WindowName", "WindowTextFallback"]
;------------------------------------------------------------------------------------

Global $g_aCfg[$ge_LASTCFG] ;Holds settings for the program

$g_aCfg[$ge_bClose] = (Cfg_Read($ge_bClose, 0) = 0 ? False : True)
$g_aCfg[$ge_bMaximize] = (Cfg_Read($ge_bMaximize, 0) = 0 ? False : True)

$g_aCfg[$ge_iMinSize] = Cfg_Read($ge_iMinSize, "0") ;Mb
$g_aCfg[$ge_iKeyDelay] = Cfg_Read($ge_iKeyDelay, 100)
$g_aCfg[$ge_iKeyDnDelay] = Cfg_Read($ge_iKeyDnDelay, 50)

$g_aCfg[$ge_sExecute] = Cfg_Read($ge_sExecute, StringTrimRight(@ScriptName, 4) & "_Orig.exe")

$g_aCfg[$ge_sActCoord] = Cfg_Read($ge_sActCoord, "0")
$g_aCfg[$ge_sInACoord] = Cfg_Read($ge_sInACoord, "0")

$g_aCfg[$ge_sSendKeysAct] = Cfg_Read($ge_sSendKeysAct, "f") ;(#Win)(+Shift)(arrow)(f)ull screen
$g_aCfg[$ge_sSendKeysInA] = Cfg_Read($ge_sSendKeysInA, "")

$g_aCfg[$ge_sActExec] = Cfg_Read($ge_sActExec, "")
$g_aCfg[$ge_sInAExec] = Cfg_Read($ge_sInAExec, "")

$g_aCfg[$ge_sFileTypes] = Cfg_Read($ge_sFileTypes, "mp4,avi,mkv,wmv") ;What files should be intercepted?
$g_aCfg[$ge_sWndName] = Cfg_Read($ge_sWndName, "VLC media player")
$g_aCfg[$ge_sWndFbTxt] = Cfg_Read($ge_sWndFbTxt, "VLC (Direct3D output)")

;------------------------------------------------------------------------------------
Global $gsMatchFileTypes = BuildFileTypes($g_aCfg[$ge_sFileTypes])
Global $gsMatchWnd = "[REGEXPTITLE:(?i)(" & $gsMatchFileTypes & ")(.*" & $g_aCfg[$ge_sWndName] & ")]"
Global $gsMatchWnd_Fb = "[REGEXPTITLE:(?i)(.*" & $g_aCfg[$ge_sWndName] & ")]" ;Fallback Matching
Global $gaWndPosAct = GetRectFromString($g_aCfg[$ge_sActCoord])
Global $gaWndPosInact = GetRectFromString($g_aCfg[$ge_sInACoord])

Global $gbActivated = False
Global $gPID = 0, $gsErr = "", $ghWndApp

_Main()
;--------------------------------------------------------------------------------------
Func _Create_Message($sMessage)
    Local $iMsg = WinAPI_RegisterWindowMessage($sMessage)
    If $iMsg = 0 Then $gsErr &= "IPC Message Creation Failure " & $sMessage & @CRLF
    Return $iMsg
EndFunc   ;==>_Create_Message

Func _Create_MessageHandler($iMsg, $sFunction)
    If $iMsg <> 0 Then
        Opt("GUIOnEventMode", 1)
        GUICreate(@ScriptName & "_IPC", 0, 0, 0, 0, 0, 0) ; create a top level window
        GUIRegisterMsg($iMsg, $sFunction)
    EndIf
EndFunc   ;==>_Create_MessageHandler

Func _Exit()
    ;sets hotkeys and saves settings
    HotKeySet("{F4}", Settings_GUI)
    HotKeySet("{F1}", _Help)
    HotKeySet("{ESC}", _Exit_Now)
    ToolTip("Pass Through F1 - Help, F4 - Settings, ESC - Quit without saving", 0, 0)
    Sleep(5000)
    ToolTip("", 0, 0)
    HotKeySet("{F4}")
    HotKeySet("{F1}")
    HotKeySet("{ESC}")
    Settings_Save()
    Exit
EndFunc   ;==>_Exit

Func _Exit_Now()
    OnAutoItExitUnRegister("_Exit")
    Exit
EndFunc   ;==>_Exit_Now

Func _Help()
    MsgBox(0, "Pass Through", "Settings stored in:" & @CRLF & $gsINI_PATH & _
            @CRLF & @CRLF & _
            "Invoked: " & @ScriptDir & "\" & $g_aCfg[$ge_sExecute] & " " & $CmdLineRaw & _
            @CRLF & "FileTypes: " & $gsMatchFileTypes & @CRLF & _
            "Errors:" & $gsErr & @CRLF)
EndFunc   ;==>_Help

Func _IsCompiled() ;wakillon
    Return @Compiled
EndFunc   ;==>_IsCompiled

Func _Main()
    If Not FileExists($gsINI_PATH) Then ;FIRST RUN
        Settings_Save()
        Settings_GUI()
    EndIf

    Opt("SendKeyDelay", $g_aCfg[$ge_iKeyDelay])
    Opt("SendKeyDownDelay", $g_aCfg[$ge_iKeyDnDelay])

    If _IsCompiled() Then
        Local $iActMsg = _Create_Message("@ScriptFullPath" & "_msg")
        RunPassThrough($iActMsg)
        _Create_MessageHandler($iActMsg, "Activated_Ext")
    EndIf

    OnAutoItExitRegister("_Exit")

    Do
        $ghWndApp = WaitActive_Wnd($gaWndPosAct, $g_aCfg[$ge_sSendKeysAct])
    Until (WaitNotExists_Wnd($ghWndApp, $gaWndPosInact, $g_aCfg[$ge_sSendKeysInA]) Or $g_aCfg[$ge_bClose])

    If $g_aCfg[$ge_bClose] And WinExists($ghWndApp) Then WinClose($ghWndApp)
    Exit
EndFunc   ;==>_Main

Func _Singleton_NOCHILD($sOccurrenceName, $iFlag = 0) ;Valik
    ;Without SECURITY_ATTRIBUTES;;;
    Local Const $ERROR_ALREADY_EXISTS = 183
    Local $aHandle = DllCall("kernel32.dll", "handle", "CreateMutexW", "struct*", 0, "bool", 1, "wstr", $sOccurrenceName)
    If @error Then Return SetError(@error, @extended, 0)
    Local $aLastError = DllCall("kernel32.dll", "dword", "GetLastError")
    If @error Then Return SetError(@error, @extended, 0)
    If $aLastError[0] = $ERROR_ALREADY_EXISTS Then
        If BitAND($iFlag, 1) Then
            DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $aHandle[0])
            If @error Then Return SetError(@error, @extended, 0)
            Return SetError($aLastError[0], $aLastError[0], 0)
        Else
            Exit -1
        EndIf
    EndIf
    Return $aHandle[0]
EndFunc   ;==>_Singleton_NOCHILD
;------------------------------------------------------------------------------------------
Func Activated_Ext() ;($hWnd, $iMsg, $wParam, $lParam)
    ;Message Posted from other instances
    ;call this to notify of an active file
    $gbActivated = True
EndFunc   ;==>Activated_Ext

Func ArrayToStr($aArray)
    ;returns single dimension array as comma delimited string
    ;on error returns 0
    Local $sRet = ""
    Local $iCt = UBound($aArray) - 1
    If $iCt < 0 Then Return SetError(1, 0, 0)
    For $i = 0 To $iCt
        $sRet &= $aArray[$i] & ","
    Next
    $sRet = StringTrimRight($sRet, 1) ;Remove the trailing ','
    Return $sRet
EndFunc   ;==>ArrayToStr

Func BuildFileTypes($sTypes)
    ;Build a regex string of file extensions from a comma separated one
    ;matches partial filenames too
    ;"txt,exe,.com,.avi,test.mp3" => ".*\.txt,.*\.exe,.*\.com,.*\.avi,.*test\.mp3"
    ;('\' escapes the '.')
    Local $sTmp, $sRet = ""
    Local $aExt = StringRegExp($sTypes, "(\w+?\.\w+)|\w+", 3)
    For $i = 0 To UBound($aExt) - 1
        $sTmp = $aExt[$i]
        If StringInStr($sTmp, ".") = 0 Then $sTmp = "." & $sTmp
        $sRet &= ".*" & StringReplace($sTmp, ".", "\.") & "|"
    Next
    $sRet = StringTrimRight($sRet, 1) ;Remove the trailing '|'
    Return $sRet
EndFunc   ;==>BuildFileTypes

Func Cfg_Read($iSetting, $sDefault)
    Return IniRead($gsINI_PATH, $gsINI_SEC, $gaIniKeys[$iSetting], $sDefault)
EndFunc   ;==>Cfg_Read

Func Cfg_Write($iSetting, $sValue)
    If Not _IsCompiled() Then
        ConsoleWrite($gaIniKeys[$iSetting] & " = " & $sValue & @CRLF)
    Else
        IniWrite($gsINI_PATH, $gsINI_SEC, $gaIniKeys[$iSetting], $sValue)
    EndIf
EndFunc   ;==>Cfg_Write

Func Execute_App($sPath)
    If FileExists( $sPath) Then
        Run(Chr(34) & $sPath & Chr(34), "")
    EndIf
EndFunc

Func GetRectFromString($sCoords)
    ;takes rect passed in string 'x, y, w, h' converts to array
    ;Returns [x, y, w, h] if string is valid or 0 if invalid
    ;You should check if return is an array with IsArray()
    Return StringRegExp($sCoords, "(\d+)\D+(\d+)\D+(\d+)\D+(\d+)", 1)
EndFunc   ;==>GetRectFromString

Func RunPassThrough($iActMsg = 0)
    ;calls the original file passing through commandline arguments
    Local $sPath = @ScriptDir & "\" & $g_aCfg[$ge_sExecute]
    Local $sSwitches = $CmdLineRaw
    ;MsgBox(0, "Pass Through", $sPath & @CRLF & $sSwitches)

    $gPID = Run(Chr(34) & $sPath & Chr(34) & " " & $sSwitches, "") ; Run

    If $gPID Then RunSingleInstance($iActMsg)

    Sleep(1000) ;Wait a moment for the file to load
EndFunc   ;==>RunPassThrough

Func RunSingleInstance($iActMsg)
    Local Const $iSZMB = (1024 * 1024)
    Local Const $HWND_BROADCAST = 0xFFFF
    If _Singleton_NOCHILD(@ScriptName, 1) = 0 Then
        If $CmdLine[0] > 1 And FileExists($CmdLine[2]) Then
            If $g_aCfg[$ge_iMinSize] And FileGetSize($CmdLine[2]) < ($g_aCfg[$ge_iMinSize] * $iSZMB) Then
                ;;;If file is less than $g_aCfg[$ge_iMinSize] Megabytes treat it like an inactive file
            ElseIf $iActMsg <> 0 Then ; Update script by posting a message from this (new) instance
                If StringRegExp($CmdLine[2], $gsMatchFileTypes) Then
                    WinAPI_PostMessage($HWND_BROADCAST, $iActMsg, 0, 0)
                EndIf
            EndIf
        EndIf
        _Exit_Now() ;single instance of script ONLY
    EndIf
EndFunc   ;==>RunSingleInstance

Func Settings_GUI()
    Opt("GUIOnEventMode", 0)
    ;GUIConstantsEx
    Local Const $GUI_ENABLE = 0x40
    Local Const $GUI_DISABLE = 0x80
    Local Const $GUI_CHECKED = 0x1
    Local Const $GUI_SHOW = 16
    Local $nMsg

    Local Enum $eS_KeySend = 0, $eS_Coords, $eS_SetWHelper, $eS_Exec, $eS_LAST
    Local $aCtlText[$eS_LAST] = ["Send Keys", "Coordinates (x, y, w, h)", "Set With Helper", "Execute"]
    Local $aActivCtls[$eS_LAST] ;Holds handles for the Active State Controls
    Local $aInactCtls[$eS_LAST] ;Holds handles for the Inactive State Controls

    Local $hForm1_1 = GUICreate("Pass Through Settings", 287, 245, 192, 124)

    GUICtrlCreateLabel($aCtlText[$eS_Exec], 8, 2, 74, 17)
    Local $hI_Exec = GUICtrlCreateInput($g_aCfg[$ge_sExecute], 100, 0, 180, 20)
    GUICtrlCreateLabel("Win Text FB", 8, 30, 74, 17)
    Local $hI_FbTxt = GUICtrlCreateInput($g_aCfg[$ge_sWndFbTxt], 100, 27, 180, 20)

    Local $hC_IClose = GUICtrlCreateCheckbox("Close on Inactive", 8, 50, 100, 17)
    GUICtrlSetState($hC_IClose, $g_aCfg[$ge_bClose] ? 1 : 4)
    GUICtrlCreateTab(8, 75, 275, 140)

    If GUICtrlCreateTabItem("Activated Settings") Then
        GUICtrlSetState(-1, $GUI_SHOW) ; will be display first
        GUICtrlCreateLabel("File Extensions", 10, 103, 74, 17)
        Local $hI_FTyp = GUICtrlCreateInput($g_aCfg[$ge_sFileTypes], 128, 100, 150, 20)

        GUICtrlCreateLabel($aCtlText[$eS_KeySend], 10, 126, 55, 20)
        $aActivCtls[$eS_KeySend] = GUICtrlCreateInput($g_aCfg[$ge_sSendKeysAct], 128, 122, 150, 20)

        GUICtrlCreateLabel($aCtlText[$eS_Exec], 10, 148, 55, 20)
        $aActivCtls[$eS_Exec] = GUICtrlCreateInput($g_aCfg[$ge_sActExec], 128, 144, 150, 20)

        GUICtrlCreateLabel($aCtlText[$eS_Coords], 10, 169, 111, 20)
        $aActivCtls[$eS_SetWHelper] = GUICtrlCreateButton($aCtlText[$eS_SetWHelper], 128, 190, 150, 17)
        $aActivCtls[$eS_Coords] = GUICtrlCreateInput(ArrayToStr($gaWndPosAct), 128, 166, 150, 20)

        Local $hC_AMaxm = GUICtrlCreateCheckbox("Maximize", 10, 189, 89, 17)
        GUICtrlSetState($hC_AMaxm, $g_aCfg[$ge_bMaximize] ? 1 : 4)
    EndIf

    If GUICtrlCreateTabItem("Inactivated Settings") Then
        GUICtrlCreateLabel($aCtlText[$eS_KeySend], 10, 103, 55, 20)
        $aInactCtls[$eS_KeySend] = GUICtrlCreateInput($g_aCfg[$ge_sSendKeysInA], 128, 100, 150, 20)

        GUICtrlCreateLabel($aCtlText[$eS_Exec], 10, 126, 55, 20)
        $aInactCtls[$eS_Exec] = GUICtrlCreateInput($g_aCfg[$ge_sInAExec], 128, 122, 150, 20)

        GUICtrlCreateLabel($aCtlText[$eS_Coords], 10, 148, 111, 20)
        $aInactCtls[$eS_SetWHelper] = GUICtrlCreateButton($aCtlText[$eS_SetWHelper], 128, 169, 150, 17)
        $aInactCtls[$eS_Coords] = GUICtrlCreateInput(ArrayToStr($gaWndPosInact), 128, 145, 150, 20)
    EndIf
    GUICtrlCreateTabItem("") ; end tabitem definition




    Local $hB_Cancel = GUICtrlCreateButton("Cancel", 8, 215, 49, 17)
    Local $hB_Save = GUICtrlCreateButton("Save", 71, 215, 49, 17)
    GUISetState(@SW_SHOW, $hForm1_1)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $hB_Cancel
                ContinueCase
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $aActivCtls[$eS_SetWHelper] ;Pops-up window to make setting coords easier
                GUICtrlSetState($aActivCtls[$eS_SetWHelper], $GUI_DISABLE)

                GUICtrlSetData($aActivCtls[$eS_Coords], Settings_PosHelper("Active Pos", _
                        GUICtrlRead($aActivCtls[$eS_Coords])))
                GUICtrlSetState($aActivCtls[$eS_SetWHelper], $GUI_ENABLE)

            Case $aInactCtls[$eS_SetWHelper] ;Pops-up window to make setting coords easier
                GUICtrlSetState($aInactCtls[$eS_SetWHelper], $GUI_DISABLE)

                GUICtrlSetData($aInactCtls[$eS_Coords], Settings_PosHelper("Inactive Pos", _
                        GUICtrlRead($aInactCtls[$eS_Coords])))
                GUICtrlSetState($aInactCtls[$eS_SetWHelper], $GUI_ENABLE)

            Case $hB_Save
                $g_aCfg[$ge_sExecute] = GUICtrlRead($hI_Exec)
                $g_aCfg[$ge_sWndFbTxt] = GUICtrlRead($hI_FbTxt)

                $g_aCfg[$ge_bClose] = (BitAND(GUICtrlRead($hC_IClose), $GUI_CHECKED) = $GUI_CHECKED) ? 1 : 0

                $g_aCfg[$ge_sFileTypes] = GUICtrlRead($hI_FTyp)
                $g_aCfg[$ge_sSendKeysAct] = GUICtrlRead($aActivCtls[$eS_KeySend])
                $g_aCfg[$ge_sActExec] = GUICtrlRead($aActivCtls[$eS_Exec])

                $g_aCfg[$ge_sActCoord] = GUICtrlRead($aActivCtls[$eS_Coords])
                $gaWndPosAct = GetRectFromString($g_aCfg[$ge_sActCoord])

                $g_aCfg[$ge_bMaximize] = (BitAND(GUICtrlRead($hC_AMaxm), $GUI_CHECKED) = $GUI_CHECKED) ? 1 : 0

                $g_aCfg[$ge_sSendKeysInA] = GUICtrlRead($aInactCtls[$eS_KeySend])
                $g_aCfg[$ge_sInAExec] = GUICtrlRead($aInactCtls[$eS_Exec])

                $g_aCfg[$ge_sInACoord] = GUICtrlRead($aInactCtls[$eS_Coords])
                $gaWndPosInact = GetRectFromString($g_aCfg[$ge_sInACoord])

                Settings_Save()
                ExitLoop
        EndSwitch
    WEnd

    GUIDelete($hForm1_1)
    Return ;
EndFunc   ;==>Settings_GUI

Func Settings_PosHelper($sTitle, $sRect)
    ;Pops-up window to make setting coords easier
    ;sRect is a string format 'x, y, w, h' OR '0'
    ;Returns new sRect in same format
    ;WindowsConstants
    Local Const $WS_OVERLAPPEDWINDOW = 0x00CF0000
    Local $nMsg
    Local $hForm1_2 = GUICreate($sTitle, 0, 0, -1, -1, $WS_OVERLAPPEDWINDOW)
    WndMoveArray($hForm1_2, GetRectFromString($sRect))

    Local $hB_Set = GUICtrlCreateButton("Set", 0, 0, 50, 17)
    GUISetState(@SW_SHOW, $hForm1_2)
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $hB_Set
                $sRect = ArrayToStr(WinGetPos($hForm1_2))
                ContinueCase
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete($hForm1_2)
    Return $sRect ;
EndFunc   ;==>Settings_PosHelper

Func Settings_Save()
    Local $vVal ;
    If Not _IsCompiled() Then ConsoleWrite("SETTINGS_SAVE:" & @CRLF)
    For $i = 0 To $ge_LASTCFG - 1
        $vVal = $g_aCfg[$i]
        If IsBool($vVal) Then
            Cfg_Write($i, $vVal ? 1 : 0)
        ElseIf IsArray($vVal) Then
            Cfg_Write($i, ArrayToStr($vVal))
        Else
            Cfg_Write($i, $vVal)
        EndIf
    Next
EndFunc   ;==>Settings_Save

Func WinAPI_PostMessage($hWnd, $iMsg, $wParam, $lParam)
    Local $aResult = DllCall("user32.dll", "bool", "PostMessage", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0]
EndFunc   ;==>WinAPI_PostMessage

Func WinAPI_RegisterWindowMessage($sMessage)
    Local $aResult = DllCall("user32.dll", "uint", "RegisterWindowMessageW", "wstr", $sMessage)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>WinAPI_RegisterWindowMessage

Func WaitActive_Wnd($aRect, $sKeys)
    ; Loops waiting for a trigger from vlc window either filename(s)
    ; in the title or window name and text
    ; if PID is defined and doesn't exist closes script
    ; Returns window handle
    Local $hWnd
    Do
        $hWnd = WndTryActivate($gsMatchWnd, "") ; Wait for active window

        If $hWnd = 0 Then ;Fallback
            $hWnd = WndTryActivate($gsMatchWnd_Fb, $g_aCfg[$ge_sWndFbTxt])
            If $hWnd <> 0 Then ExitLoop
            If $gPID And Not ProcessExists($gPID) And Not WinExists($gsMatchWnd) Then Exit
            Sleep(1000)
        EndIf
    Until ($hWnd <> 0)

    WndMoveArray($hWnd, $aRect)
    WndSendKeys($hWnd, $sKeys)

    If $g_aCfg[$ge_bMaximize] Then WinSetState($hWnd, "", @SW_MAXIMIZE)

    Execute_App($g_aCfg[$ge_sActExec])
    Return $hWnd
EndFunc   ;==>WaitActive_Wnd

Func WaitNotExists_Wnd($hWnd, $aRect, $sKeys)
    ;Returns False if Title Does Not exist but $hWnd DOES exist
    ;Returns True if $hWnd + $title DOES NOT exist
    Do
        $gbActivated = False
        WinWaitClose(WinGetTitle($ghWndApp))
    Until (Not $gbActivated) ;can be overidden by message posted from another instance

    If WinExists($hWnd) Then
        WndSendKeys($hWnd, $sKeys)

        If $g_aCfg[$ge_bMaximize] Then WinSetState($hWnd, "", @SW_RESTORE)

        WndMoveArray($hWnd, $aRect)
        Execute_App($g_aCfg[$ge_sInAExec])
        Return False
    EndIf
    Return True
EndFunc   ;==>WaitNotExists_Wnd

Func WndMoveArray($hWnd, $aC)
    ;Moves $hWnd to coords specified by array
    If UBound($aC) >= 4 Then
        WinMove($hWnd, "", $aC[0], $aC[1], $aC[2], $aC[3])
    EndIf
EndFunc   ;==>WndMoveArray

Func WndSendKeys($hWnd, $sKeys)
    If $sKeys <> "" Then
        ControlSend($hWnd, "", 0, $sKeys)
        Sleep(100)
    EndIf
EndFunc   ;==>WndSendKeys

Func WndTryActivate($Title, $Text = "")
    ;attemps to activate a window / waits $giACTWAIT seconds for window to become active
    WinActivate($Title, $Text)
    Local $hWnd = WinWaitActive($Title, $Text, $giACTWAIT) ; Wait for active window for number of seconds
    Return $hWnd
EndFunc   ;==>WndTryActivate

 

VLCMOVER.png

Edited by Bilgus
Posted an older version of the script
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...