@chinagreenelvis, depending on what the rest of your code does, it might be easier to use indeed. One downside is that it's more difficult to change the number of columns, as both monitor AND column info are tied together. Whether that matters to you depends on your code.
I opted to change Maps to Objects as you are defining properties for monitors, and in such situations my personal preference is using object notation. Also Maps are case-sensitive by default, so
Monitor["Left"] is not the same as
Monitor["left"], whereas
Monitor.Left == Monitor.left. See further discussion of Maps vs Objects here:
viewtopic.php?style=7&t=120410.
Code: Select all
#Requires AutoHotkey v2
#SingleInstance Force
Persistent
SetWorkingDir A_ScriptDir
Thread "NoTimers", True
SetTimer MonitorTimer, 300
Monitors := []
MonitorTimer() {
static SM_CMONITORS := 80
global Monitors
NumMonitors := SysGet(SM_CMONITORS)
; Get current status of monitors
CurrentMonitors := []
Loop NumMonitors {
MonitorNumber := A_Index
ActualN := MonitorGet(MonitorNumber, &Left, &Top, &Right, &Bottom)
CurrentMonitors.Push({Left:Left, Top:Top, Right:Right, Bottom:Bottom, Columns:[]})
}
if NumMonitors != Monitors.Length {
if Monitors.Length
MsgBox "Number of Monitors Changed"
else
MsgBox "First run (or no monitors)"
} else {
for i, Monitor in CurrentMonitors {
Monitor.Columns := Monitors[i].Columns
if Monitor.Left != Monitors[i].Left ||
Monitor.Top != Monitors[i].Top ||
Monitor.Right != Monitors[i].Right ||
Monitor.Bottom != Monitors[i].Bottom
{
;; Do a thing here
SoundBeep 300, 500
}
}
}
; Rewrite old monitor info with new monitor info
Monitors := CurrentMonitors
}