Please don't mark as duplicate before reading the whole thing. I have read the other posts and they do not solve my issue.
I'm using a laptop with an external display. When the display is connected, I would like closing the lid to do nothing. However, when the display is not connected, I would like closing the lid to make the laptop go to sleep.
What I'm doing now is setting 'close the lid' to 'do nothing' in my settings when I'm using the external display, and try to remember to set it back once I disconnect the display. But I often forget and then my laptop stays on for hours when I think it's gone to sleep, draining battery.
I already use autohotkey so if there is a simple way to detect an external display in AutoHotkey that would be a start. Then I could create two power plans and switch between them (is that possible in AutoHotkey?).
I have already tried sysget, MonitorCount but that does not work because the number of monitors is 1 both when I have only the external monitor and when I have only the laptop monitor.