13

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.

4 Answers 4

1

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.
1
  • 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. Commented May 3, 2019 at 6:36
0

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.

0

Not a full answer, but perhaps some pointers:

Monitors have names, For example, here is a screenshot from a program I use to change my monitor brightness on demand by use of taskbar and shotcut called ClickMonitorDDC:

A screenshot showing the names of two connected monitors: The internal laptop one and a connected Dell one.

screenshot

Here is something I found using autohotkey for finding model numbers in AutoHotKey.

And finally, here is something about changing power plans through AutoHotKey.

0

Note: I'm not an autohotkey user.

Here's what I found at this link?

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force

; Defines getMonitorInputSource
; Finds monitor handle
getMonitorHandle()
{
  ; Initialize Monitor handle
  hMon := DllCall("MonitorFromPoint"
    , "int64", 0 ; point on monitor
    , "uint", 1) ; flag to return primary monitor on failure

    
  ; Get Physical Monitor from handle
  VarSetCapacity(Physical_Monitor, 8 + 256, 0)

  DllCall("dxva2\GetPhysicalMonitorsFromHMONITOR"
    , "int", hMon   ; monitor handle
    , "uint", 1   ; monitor array size
    , "int", &Physical_Monitor)   ; point to array with monitor

  return hPhysMon := NumGet(Physical_Monitor)
}

destroyMonitorHandle(handle)
{
  DllCall("dxva2\DestroyPhysicalMonitor", "int", handle)
}

getMonitorInputSource()
{
  handle := getMonitorHandle()
  DllCall("dxva2\GetVCPFeatureAndVCPFeatureReply"
    , "int", handle
    , "char", 0x60 ;VCP code for Input Source Select
    , "Ptr", 0
    , "uint*", currentValue
    , "uint*", maximumValue)
  destroyMonitorHandle(handle)
  return currentValue
}

MouseLock := False

!+l::
    If (!MouseLock && getMonitorInputSource() == 4) {
        MouseLock := True
        BlockInput, MouseMove
        return
        }

    Else {
        MouseLock := False
        BlockInput, MouseMoveOff
        return
        }

#If (getMonitorInputSource() == 4 && !MouseLock)
XButton2::
    If (!WinExist("ahk_exe Magnify.exe")) {
        Send, #=
        return
        }
    If (WinExist("ahk_exe Magnify.exe")) {
        Send, #{Esc}
        return
        }

#If (getMonitorInputSource() == 4 && MouseLock)
XButton2::
    If (!WinExist("ahk_exe Magnify.exe")) {
        Send, #=
        BlockInput, MouseMoveOff
        return
        }
    If (WinExist("ahk_exe Magnify.exe")) {
        Send, #{Esc}
        BlockInput, MouseMove
        return
        }
2
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review Commented Jan 13, 2022 at 6:22
  • @DarkDiamond -- apologies, as you can see I'm a new contributor. How does the above solution re-write look? Commented Jan 13, 2022 at 21:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .