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.


I don't know any solid answers to your problem. But there are a few things you could try:

  1. Briefly plugging the laptop in before closing it. You could set closing the lid to do nothing when plugged in, but sleep if not plugged in. So when you are using your monitor, you could plug in the laptop, close the lid, and then unplug it (The laptop will stay awake.)
  2. Closing the laptop right after turning it on. In my experience, if you close the laptop immediately after powering it on, it won't go to sleep. (Probably because Windows hasn't yet loaded up any of the processes that tell it to sleep when you close the lid.)
  3. Pressing the shortcut key "[WIN]+X,U,S" to sleep One of my computers will not do anything but shut down when I close the lid, so I have gotten into the habit of using the sleep shortcut: Hold down the Windows key and press "x". Release, and then press the keys "u" and "s" without holding down. Once you get the hang of it, using this shortcut can be a lot more efficient than going into the start menu to sleep the computer.
| improve this answer | |
  • Note that, while your first and second answers may work on a wide range of Windows versions, the third one will not; Windows 7 has a different Win+X function. – Scott May 3 '19 at 6:36

You can of course do anything in AHK basically. You can create plans, snip a tiny screenshot of the exact button and location you would like to enable, and then script an AHK script to open the power dialog, search for that exact plan based on your png/jpg, click it, then close the power dialog.

This may not be the best option, but it is an option. You may look into scheduled tasks, as I believe taskschd.msc has the ability to determine current power plan.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.