Тема: AHK: Запуск окна с перемещением
Добрый день! В самом низу приведен скрипт, который производит перемещение окон влево или вправо по клавишам "Alt+[" и "Alt+]".
Также на горячую клавишу "1" добавлен код, который запускает окно с диском "C:\" и разворачивает его слева экрана:
1::
Run Explorer.exe /n`,"C:\",,,WID
WinWait, ahk_class CabinetWClass, , 3
if ErrorLevel
return
WinWaitActive, ahk_class CabinetWClass
WinActivate, ahk_class CabinetWClass
gosub, LftHlfSub
return
Возник вопрос - как на AHK запускать это окно сразу в развернутом слева состоянии?
; Move and Resize Active Window to LEFT HALF of Current Monitor
![::
LftHlfSub:
{
; If Focus is on an Exluded Program (I.e.Desktop), Ignore this HotKey
GoSub, ExcludPrgrm
If (IgnorePrgrm == True)
{
Return
}
; Retrieve Coordinates, Dimensions, Min/Max State, Process Name and Title of Active Window
WinGetPos, WinLft, WinTop, WinWdt, WinHgt, A
WinGet, WinMMax, MinMax, A
WinGet, PNameHlfLft, ProcessName, A
WinGetTitle, TNameHlfLft, A
; Add Correction Factor per Program + Find in which Monitor Active Window is located
WinGet, PNameWin, ProcessName, A
{
HrzCrctn = -14
HgtCrctn = 8
WdtCrctn = 30
}
; Retrieves on which Monitor Number the Active Window is on
GoSub, WinCurntMon
; If Window is Maximized, "UnMaximize" it
;!!If (WinMMax == 1)
{
WinRestore, A
}
; Move and Resize Active Window to Left Half of Current Monitor
WinMove, A, , MonLft[OnMonitor] + HrzCrctn, MonTop[OnMonitor], MonHlfWdt[OnMonitor] + WdtCrctn, MonHgt[OnMonitor] + HgtCrctn
Return
}
; Move and Resize Active Window to RIGHT HALF of Current Monitor
!]::
RgtHlfSub:
{
; If Focus is on an Exluded Program (I.e.Desktop), Ignore this HotKey
GoSub, ExcludPrgrm
If (IgnorePrgrm == True)
{
Return
}
; Retrieve Coordinates, Dimensions, Min/Max State, Process Name and Title of Active Window
WinGetPos, WinLft, WinTop, WinWdt, WinHgt, A
WinGet, WinMMax, MinMax, A
WinGet, PNameHlfLft, ProcessName, A
WinGetTitle, TNameHlfLft, A
; Add Correction Factor per Program + Find in which Monitor Active Window is located
WinGet, PNameWin, ProcessName, A
{
HrzCrctn = 2
HgtCrctn = 8
WdtCrctn = 10
}
; Retrieves on which Monitor Number the Active Window is on
GoSub, WinCurntMon
; If Window is Maximized, "UnMaximize" it
;!!If (WinMMax == 1)
{
WinRestore, A
}
; If Active Window is already Resized and Located on Left Half of the Current Monitor, Move Active Window to Right Half of Previous Monitor
WinMove, A, , MonHlfRgt[MonQty] + HrzCrctn, MonTop[MonQty], MonHlfWdt[MonQty] + WdtCrctn, MonHgt[MonQty] + HgtCrctn
Return
}
; User Defined Values and Programs
; ****************************************
; ***** Gosub Label *****
; Exluded Programs, where the HotKeys will NOT WORK
ExcludPrgrm:
{
WinGetClass, CNameHlfLft, A
ExcludPrgrm := False
; WorkerW ➔ Desktop
If (CNameHlfLft == "WorkerW")
{
IgnorePrgrm := True
}
Return
}
; ***** Gosub Label *****
; Retrieves on which Monitor Number the Active Window is on
; Used to Move Window from Right to Left Monitors
WinCurntMon:
{
WinGetPos, WinHrz, WinVrt, WinWdt, WinHgt, A
WinHgtCtr := WinVrt + WinHgt / 2
WinHrzCtr := WinHrz + WinWdt / 2
Loop, %MonQty%
{
; If Center of Active Window is Located between defined Boundaries, Active Window is Located on Monitor #X
If (WinHgtCtr >= MonTop[A_Index] AND WinHgtCtr <= MonBtm[A_Index] AND WinHrzCtr >= MonLft[A_Index] AND WinHrzCtr <= MonRgt[A_Index])
{
OnMonitor := A_Index
; Once Matching Monitor Found, Stop the Search
Break
}
}
Return
}
onstart:
; *********************************************************************************
; Automatic Mapping of All Monitors, Move & Resize Windows -START-
; *********************************************************************************
; Initialization of Arrays used
; Variables used for Temporary Monitor Number used to later organize Monitors in Ascending Order
; (1D Arrays)
MonTopTemp := []
MonBtmTemp := []
MonLftTemp := []
MonRgtTemp := []
; Variables used for Definitive Monitor Number in Ascending Order
; (1D Arrays)
MonTop := []
MonBtm := []
MonLft := []
MonRgt := []
; Variables used for Monitor Dimensions for Resizing to Half or Monitor and for Moving to another Monitor
; (1D Arrays)
MonHlfLft := []
MonHlfRgt := []
MonWdt := []
MonHlfWdt := []
MonHgt := []
; Variables of Definitive Monitor Number used to Move Windows Up and Down between Rows
; (2D Arrays)
MtxTop := []
MtxBtm := []
MtxLft := []
MtxRgt := []
MtxWdt := []
MtxHgt := []
MtxLstRow := []
MtxRowQty := []
Col_RowQty := []
; Variables used for Monitor Dimensions for Resizing to Quadrant of Monitor per Monitor Number
; (2D Arrays)
MonQdrTop := []
MonQdrLft := []
MonQdrBtm := []
MonQdrRgt := []
MonQdrWdt := []
MonQdrHgt := []
; Variables used for Monitor Dimensions for Resizing to Quadrant of Monitor per Column
; (3D Arrays)
MtxQdrTop := []
MtxQdrLft := []
MtxQdrBtm := []
MtxQdrRgt := []
MtxQdrWdt := []
MtxQdrHgt := []
; Variables used for Row Alignment with Bottom of Monitors
MonDIMBtmT := []
; Retrieve the Quantity of Monitors connected to system
SysGet, MonQty, MonitorCount
; Retrieve Coordinates and Dimensions of each Monitor
Loop, %MonQty%
{
SysGet, MonWRKA, MonitorWorkArea, %A_Index%
SysGet, MonDIM, Monitor, %A_Index%
MonTopTemp[A_Index] := MonWRKATop
MonBtmTemp[A_Index] := MonWRKABottom
MonLftTemp[A_Index] := MonWRKALeft
MonRgtTemp[A_Index] := MonWRKARight
RowCntTemp = %RowCntTemp%, %MonWRKATop%
ColCntTemp = %ColCntTemp%, %MonWRKALeft%
; Variables used for Row Alignment with Bottom of Monitors
; Options to Define Rows with Bottom of Monitors are Indicated Further in the Script
MonDIMBtmT[A_Index] := MonDIMBottom
RowCntBtmT = %RowCntBtmT%, %MonDIMBottom%
}
; Trim the first character (a comma ",")
StringTrimLeft, RowCnt, RowCntTemp, 1
StringTrimLeft, ColCnt, ColCntTemp, 1
; Bottom of Row Alignment
StringTrimLeft, RowBtmCnt, RowCntBtmT, 1
; List out each unique value of Row and Column, defining boundaries
Sort RowCnt, N U D,
Sort ColCnt, N U D,
; Bottom of Row Alignment
Sort RowBtmCnt, N U D,
; Count the number of Rows and Columns
Loop, Parse, RowCnt, `,
{
RowQty := A_Index
}
Loop, Parse, ColCnt, `,
{
ColQty := A_Index
}
; Bottom of Row Alignment
Loop, Parse, RowBtmCnt, `,
{
RowBtmQty := A_Index
}
; Separates each value of Row and Column into an Array Variable
RowValues := StrSplit(RowCnt, ",", " ")
ColValues := StrSplit(ColCnt, ",", " ")
; Bottom of Row Alignment
RowBtmValues := StrSplit(RowBtmCnt, ",", " ")
; ***** Monitor Mapping Initialization *****
; After counting how many Rows and Columns there are, the script will verify if
; there is a Monitor in each of the Rows/Columns Positions. If there is a gap
; (no Monitor in a Row/Column), the Space should not register in the Mapping
; Counter to Assign Monitor Number, from Top Left to Bottom Right
MonOrdr := 1
Loop, %RowQty%
; ******************************************************************
; Option ➔ Bottom of Row Alignment / Put in Comments the Line above
; Loop, %RowBtmQty%
; ******************************************************************
{
; Keep the current Row in Memory
RowPosA_Index := A_Index
Loop, %ColQty%
{
; Keep the current Column in Memory
ColPosA_Index := A_Index
Loop, %MonQty%
{
; Keep the current Monitor Number in Memory
MonNrA_Index := A_Index
If (ColValues[ColPosA_Index] == MonLftTemp[MonNrA_Index] AND RowValues[RowPosA_Index] == MonTopTemp[MonNrA_Index])
; *********************************************************************************************************************
; Option ➔ Bottom of Row Alignment / Put in Comments the Line above
; If (ColValues[ColPosA_Index] == MonLftTemp[MonNrA_Index] AND RowBtmValues[RowPosA_Index] == MonDIMBtmT[MonNrA_Index])
; *********************************************************************************************************************
{
; Assign COORDINATES and DIMENSIONS of Monitors in Order, per MONITOR NUMBER, from Top Left to Bottom Right
MonTop[MonOrdr] := MonTopTemp[MonNrA_Index]
MonLft[MonOrdr] := MonLftTemp[MonNrA_Index]
MonBtm[MonOrdr] := MonBtmTemp[MonNrA_Index]
MonRgt[MonOrdr] := MonRgtTemp[MonNrA_Index]
; Calculate COORDINATES and DIMENSIONS, per MONITOR NUMBER, to move Window to HALF OF MONITOR and to Another Monitor
MonHlfLft[MonOrdr] := MonLft[MonOrdr]
MonHlfRgt[MonOrdr] := Floor((MonLft[MonOrdr] + MonRgt[MonOrdr]) / 2)
MonWdt[MonOrdr] := MonRgt[MonOrdr] - MonLft[MonOrdr]
MonHlfWdt[MonOrdr] := Floor((MonRgt[MonOrdr] - MonLft[MonOrdr]) / 2)
MonHgt[MonOrdr] := MonBtm[MonOrdr] - MonTop[MonOrdr]
; ***** For Each Monitor Found, Assign Coordinates and Dimensions to 4 Quadrants *****
; Quadrant Q1 of Current Monitor: TOP LEFT
MonQdrTop[MonOrdr, 1] := MonTopTemp[MonNrA_Index]
MonQdrLft[MonOrdr, 1] := MonLftTemp[MonNrA_Index]
MonQdrBtm[MonOrdr, 1] := Floor(MonBtmTemp[MonNrA_Index] / 2)
MonQdrRgt[MonOrdr, 1] := Floor(MonRgtTemp[MonNrA_Index] / 2)
MonQdrWdt[MonOrdr, 1] := Floor((MonRgtTemp[MonNrA_Index] - MonLftTemp[MonNrA_Index]) / 2)
MonQdrHgt[MonOrdr, 1] := Floor((MonBtmTemp[MonNrA_Index] - MonTopTemp[MonNrA_Index]) / 2)
; Quadrant Q2 of Current Monitor: BOTTOM LEFT
MonQdrTop[MonOrdr, 2] := Floor(MonTopTemp[MonNrA_Index] + (MonBtmTemp[MonNrA_Index] - MonTopTemp[MonNrA_Index]) / 2)
MonQdrLft[MonOrdr, 2] := MonLftTemp[MonNrA_Index]
MonQdrBtm[MonOrdr, 2] := MonBtmTemp[MonNrA_Index]
MonQdrRgt[MonOrdr, 2] := Floor(MonRgtTemp[MonNrA_Index] / 2)
MonQdrWdt[MonOrdr, 2] := Floor((MonRgtTemp[MonNrA_Index] - MonLftTemp[MonNrA_Index]) / 2)
MonQdrHgt[MonOrdr, 2] := Floor((MonBtmTemp[MonNrA_Index] - MonTopTemp[MonNrA_Index]) / 2)
; Quadrant Q3 of Current Monitor: TOP RIGHT
MonQdrTop[MonOrdr, 3] := MonTopTemp[MonNrA_Index]
MonQdrLft[MonOrdr, 3] := Floor(MonLftTemp[MonNrA_Index] + (MonRgtTemp[MonNrA_Index] - MonLftTemp[MonNrA_Index]) / 2)
MonQdrBtm[MonOrdr, 3] := Floor(MonBtmTemp[MonNrA_Index] / 2)
MonQdrRgt[MonOrdr, 3] := MonRgtTemp[MonNrA_Index]
MonQdrWdt[MonOrdr, 3] := Floor((MonRgtTemp[MonNrA_Index] - MonLftTemp[MonNrA_Index]) / 2)
MonQdrHgt[MonOrdr, 3] := Floor((MonBtmTemp[MonNrA_Index] - MonTopTemp[MonNrA_Index]) / 2)
; Quadrant Q4 of Current Monitor: BOTTOM RIGHT
MonQdrTop[MonOrdr, 4] := Floor(MonTopTemp[MonNrA_Index] + (MonBtmTemp[MonNrA_Index] - MonTopTemp[MonNrA_Index]) / 2)
MonQdrLft[MonOrdr, 4] := Floor(MonLftTemp[MonNrA_Index] + (MonRgtTemp[MonNrA_Index] - MonLftTemp[MonNrA_Index]) / 2)
MonQdrBtm[MonOrdr, 4] := MonBtmTemp[MonNrA_Index]
MonQdrRgt[MonOrdr, 4] := MonRgtTemp[MonNrA_Index]
MonQdrWdt[MonOrdr, 4] := Floor((MonRgtTemp[MonNrA_Index] - MonLftTemp[MonNrA_Index]) / 2)
MonQdrHgt[MonOrdr, 4] := Floor((MonBtmTemp[MonNrA_Index] - MonTopTemp[MonNrA_Index]) / 2)
; ****************************************************************************
; When a Monitor is found at this ROW and COLUMN Position, increment Count for Next Monitor
MonOrdr += 1
; Once Matching Monitor Found, Skip to Next Column
Break
}
}
}
}
; ***** Monitor Mapping Initialization *****
; This part of the Script will Organize Monitors in Order, from Top to Bottom
Loop, %ColQty%
{
ColPosA_Index := A_Index
; On every new Column, Start Counting Rows at 1
VrtMonOrdr := 1
Loop, %RowQty%
; ******************************************************************
; Option ➔ Bottom of Row Alignment / Put in Comments the Line above
; Loop, %RowBtmQty%
; ******************************************************************
{
RowPosA_Index := A_Index
Loop, %MonQty%
{
VrtMonNrA_Index := A_Index
If (ColValues[ColPosA_Index] == MonLftTemp[VrtMonNrA_Index] AND RowValues[RowPosA_Index] == MonTopTemp[VrtMonNrA_Index])
; ***************************************************************************************************************************
; Option ➔ Bottom of Row Alignment / Put in Comments the Line above
; If (ColValues[ColPosA_Index] == MonLftTemp[VrtMonNrA_Index] AND RowBtmValues[RowPosA_Index] == MonDIMBtmT[VrtMonNrA_Index])
; ***************************************************************************************************************************
{
; Assign COORDINATES and DIMENSIONS of Monitors in Order, per ROW and COLUMN COLUMN (MATRIX), from Top to Bottom for each Column
MtxTop[VrtMonOrdr, ColPosA_Index] := MonTopTemp[VrtMonNrA_Index]
MtxLft[VrtMonOrdr, ColPosA_Index] := MonLftTemp[VrtMonNrA_Index]
MtxBtm[VrtMonOrdr, ColPosA_Index] := MonBtmTemp[VrtMonNrA_Index]
MtxRgt[VrtMonOrdr, ColPosA_Index] := MonRgtTemp[VrtMonNrA_Index]
; Calculate COORDINATES and DIMENSIONS, per ROW and COLUMN COLUMN (MATRIX), to move Window to Another Monitor
MtxWdt[VrtMonOrdr, ColPosA_Index] := MonRgtTemp[VrtMonNrA_Index] - MonLftTemp[VrtMonNrA_Index]
MtxHgt[VrtMonOrdr, ColPosA_Index] := MonBtmTemp[VrtMonNrA_Index] - MonTopTemp[VrtMonNrA_Index]
; ***** For Each Monitor Found, Assign Coordinates and Dimensions to 4 Quadrants *****
; Quadrant Q1 of Current Monitor: TOP LEFT
; Floor Function to be used in case there is a division of an odd number which would leave a "0.5". Comparisons (Full Height and Quadrants) do not work without it.
MtxQdrTop[VrtMonOrdr, ColPosA_Index, 1] := MonTopTemp[VrtMonNrA_Index]
MtxQdrLft[VrtMonOrdr, ColPosA_Index, 1] := MonLftTemp[VrtMonNrA_Index]
MtxQdrBtm[VrtMonOrdr, ColPosA_Index, 1] := Floor(MonBtmTemp[VrtMonNrA_Index] / 2)
MtxQdrRgt[VrtMonOrdr, ColPosA_Index, 1] := Floor(MonRgtTemp[VrtMonNrA_Index] / 2)
MtxQdrWdt[VrtMonOrdr, ColPosA_Index, 1] := Floor((MonRgtTemp[VrtMonNrA_Index] - MonLftTemp[VrtMonNrA_Index]) / 2)
MtxQdrHgt[VrtMonOrdr, ColPosA_Index, 1] := Floor((MonBtmTemp[VrtMonNrA_Index] - MonTopTemp[VrtMonNrA_Index]) / 2)
; Quadrant Q2 of Current Monitor: BOTTOM LEFT
MtxQdrTop[VrtMonOrdr, ColPosA_Index, 2] := Floor(MonTopTemp[VrtMonNrA_Index] + (MonBtmTemp[VrtMonNrA_Index] - MonTopTemp[VrtMonNrA_Index]) / 2)
MtxQdrLft[VrtMonOrdr, ColPosA_Index, 2] := MonLftTemp[VrtMonNrA_Index]
MtxQdrBtm[VrtMonOrdr, ColPosA_Index, 2] := MonBtmTemp[VrtMonNrA_Index]
MtxQdrRgt[VrtMonOrdr, ColPosA_Index, 2] := Floor(MonRgtTemp[VrtMonNrA_Index] / 2)
MtxQdrWdt[VrtMonOrdr, ColPosA_Index, 2] := Floor((MonRgtTemp[VrtMonNrA_Index] - MonLftTemp[VrtMonNrA_Index]) / 2)
MtxQdrHgt[VrtMonOrdr, ColPosA_Index, 2] := Floor((MonBtmTemp[VrtMonNrA_Index] - MonTopTemp[VrtMonNrA_Index]) / 2)
; Quadrant Q3 of Current Monitor: TOP RIGHT
MtxQdrTop[VrtMonOrdr, ColPosA_Index, 3] := MonTopTemp[VrtMonNrA_Index]
MtxQdrLft[VrtMonOrdr, ColPosA_Index, 3] := Floor(MonLftTemp[VrtMonNrA_Index] + (MonRgtTemp[VrtMonNrA_Index] - MonLftTemp[VrtMonNrA_Index]) / 2)
MtxQdrBtm[VrtMonOrdr, ColPosA_Index, 3] := Floor(MonBtmTemp[VrtMonNrA_Index] / 2)
MtxQdrRgt[VrtMonOrdr, ColPosA_Index, 3] := MonRgtTemp[VrtMonNrA_Index]
MtxQdrWdt[VrtMonOrdr, ColPosA_Index, 3] := Floor((MonRgtTemp[VrtMonNrA_Index] - MonLftTemp[VrtMonNrA_Index]) / 2)
MtxQdrHgt[VrtMonOrdr, ColPosA_Index, 3] := Floor((MonBtmTemp[VrtMonNrA_Index] - MonTopTemp[VrtMonNrA_Index]) / 2)
; Quadrant Q4 of Current Monitor: BOTTOM RIGHT
MtxQdrTop[VrtMonOrdr, ColPosA_Index, 4] := Floor(MonTopTemp[VrtMonNrA_Index] + (MonBtmTemp[VrtMonNrA_Index] - MonTopTemp[VrtMonNrA_Index]) / 2)
MtxQdrLft[VrtMonOrdr, ColPosA_Index, 4] := Floor(MonLftTemp[VrtMonNrA_Index] + (MonRgtTemp[VrtMonNrA_Index] - MonLftTemp[VrtMonNrA_Index]) / 2)
MtxQdrBtm[VrtMonOrdr, ColPosA_Index, 4] := MonBtmTemp[VrtMonNrA_Index]
MtxQdrRgt[VrtMonOrdr, ColPosA_Index, 4] := MonRgtTemp[VrtMonNrA_Index]
MtxQdrWdt[VrtMonOrdr, ColPosA_Index, 4] := Floor((MonRgtTemp[VrtMonNrA_Index] - MonLftTemp[VrtMonNrA_Index]) / 2)
MtxQdrHgt[VrtMonOrdr, ColPosA_Index, 4] := Floor((MonBtmTemp[VrtMonNrA_Index] - MonTopTemp[VrtMonNrA_Index]) / 2)
; ****************************************************************************
; Assign Numbering to Monitor on this Column
Col_RowQty[ColPosA_Index] := VrtMonOrdr
; When a Monitor is found at this ROW and COLUMN Position, increment Count for Next Monitor in this Column
VrtMonOrdr += 1
; Once Matching Monitor Found, Skip to Next Row
Break
}
}
}
}
return