Code:
#UseHook On
GetMonitorIndexFromWindow(windowHandle)
{
; Starts with 1.
monitorIndex := 1
VarSetCapacity(monitorInfo, 40)
NumPut(40, monitorInfo)
if (monitorHandle := DllCall("MonitorFromWindow", "uint", windowHandle, "uint", 0x2))
&& DllCall("GetMonitorInfo", "uint", monitorHandle, "uint", &monitorInfo)
{
monitorLeft := NumGet(monitorInfo, 4, "Int")
monitorTop := NumGet(monitorInfo, 8, "Int")
monitorRight := NumGet(monitorInfo, 12, "Int")
monitorBottom := NumGet(monitorInfo, 16, "Int")
workLeft := NumGet(monitorInfo, 20, "Int")
workTop := NumGet(monitorInfo, 24, "Int")
workRight := NumGet(monitorInfo, 28, "Int")
workBottom := NumGet(monitorInfo, 32, "Int")
isPrimary := NumGet(monitorInfo, 36, "Int") & 1
SysGet, monitorCount, MonitorCount
Loop, %monitorCount%
{
SysGet, tempMon, Monitor, %A_Index%
; Compare location to determine the monitor index.
if ((monitorLeft = tempMonLeft) and (monitorTop = tempMonTop)
and (monitorRight = tempMonRight) and (monitorBottom = tempMonBottom))
{
monitorIndex := A_Index
break
}
}
}
return monitorIndex
}
+PrintScreen::
SysGet, Mon1, Monitor, 1
priW:= (Mon1Right - Mon1Left)
priH:= (Mon1Bottom - Mon1Top)
SysGet, Mon2, Monitor, 2
secW:= (Mon2Right - Mon2Left)
secH:= (Mon2Bottom - Mon2Top)
WinGet, TempWindowID, ID, A
scridx := GetMonitorIndexFromWindow(TempWindowID)
;MsgBox, 0,, %scridx%
If (WindowID != TempWindowID)
{
WindowID:=TempWindowID
WindowState:=0
}
If (WindowState != 1)
{
WinGetPos, WinPosX, WinPosY, WindowWidth, WindowHeight, ahk_id %WindowID%
WinSet, Style, -0xC40000, ahk_id %WindowID%
If (scridx = 1)
{
WinMove, ahk_id %WindowID%, , 0, 0, priW, priH
}
If (scridx = 2)
{
WinMove, ahk_id %WindowID%, , priW, 0, secW, secH
}
;Hide Windows Task Bar and Start Button. (Remove the following two lines if you don't want that behaviour)
;WinHide ahk_class Shell_TrayWnd
;WinHide Start ahk_class Button
}
Else
{
WinSet, Style, +0xC40000, ahk_id %WindowID%
WinMove, ahk_id %WindowID%, , WinPosX, WinPosY, WindowWidth, WindowHeight
;Show the task bar again
;WinShow ahk_class Shell_TrayWnd
;WinShow Start ahk_class Button
}
WindowState:=!WindowState
return
+ScrollLock::
SysGet, Mon1, Monitor, 1
secW:= (Mon1Right - Mon1Left)
secH:= (Mon1Bottom - Mon1Top)
SysGet, Mon2, Monitor, 2
priW:= (Mon2Right - Mon2Left)
priH:= (Mon2Bottom - Mon2Top)
WinGet, TempWindowID, ID, A
scridx := GetMonitorIndexFromWindow(TempWindowID)
;MsgBox, 0,, %scridx%
If (WindowID != TempWindowID)
{
WindowID:=TempWindowID
WindowState:=0
}
If (WindowState != 1)
{
WinGetPos, WinPosX, WinPosY, WindowWidth, WindowHeight, ahk_id %WindowID%
WinSet, Style, -0xC40000, ahk_id %WindowID%
If (scridx = 2)
{
WinMove, ahk_id %WindowID%, , 0, 0, priW, priH
}
If (scridx = 1)
{
WinMove, ahk_id %WindowID%, , -secW, 0, secW, secH
}
;Hide Windows Task Bar and Start Button. (Remove the following two lines if you don't want that behaviour)
;WinHide ahk_class Shell_TrayWnd
;WinHide Start ahk_class Button
}
Else
{
WinSet, Style, +0xC40000, ahk_id %WindowID%
WinMove, ahk_id %WindowID%, , WinPosX, WinPosY, WindowWidth, WindowHeight
;Show the task bar again
;WinShow ahk_class Shell_TrayWnd
;WinShow Start ahk_class Button
}
WindowState:=!WindowState
return
Bookmarks