motionman95 Posted May 25, 2009 Share Posted May 25, 2009 (edited) Kenny (ken82m) and I were discussing via PM methods that might allow someone to detect when the laptop lid closes.We were wondering if this method might work:I don't think windows has an API for it - but, according to this and this, ExRegisterCallback or DxgkDdiNotifyAcpiEvent can be used to get PO_CB_LID_SWITCH_STATE, which returns 1 or 0 based on the state of the laptop lid.Edit:This may help as well. Edited May 25, 2009 by motionman95 Link to comment Share on other sites More sharing options...
motionman95 Posted May 25, 2009 Author Share Posted May 25, 2009 Bump Link to comment Share on other sites More sharing options...
Authenticity Posted May 25, 2009 Share Posted May 25, 2009 The screen is turned off when the lid is closed? Link to comment Share on other sites More sharing options...
motionman95 Posted May 25, 2009 Author Share Posted May 25, 2009 I'm not sure - I think so... Link to comment Share on other sites More sharing options...
martin Posted May 25, 2009 Share Posted May 25, 2009 (edited) The screen is turned off when the lid is closed? If the laptop is set to hibernate when the lid is closed you could check the $WM_POWERBROADCAST message. expandcollapse popup#include <GUIConstantsEx.au3> Global Const $WM_POWERBROADCAST = 0x218 Global Const $PBT_APMRESUMEAUTOMATIC = 0x12 Global Const $PBT_APMQUERYSUSPEND = 0x0000 Global Const $PBT_APMQUERYSTANDBY = 0x0001 Global Const $PBT_APMQUERYSUSPENDFAILED = 0x0002 Global Const $PBT_APMQUERYSTANDBYFAILED = 0x0003 Global Const $PBT_APMSUSPEND = 0x0004 Global Const $PBT_APMSTANDBY = 0x0005 Global Const $PBT_APMRESUMECRITICAL = 0x0006 Global Const $PBT_APMRESUMESUSPEND = 0x0007 Global Const $PBT_APMRESUMESTANDBY = 0x0008 Global Const $PBTF_APMRESUMEFROMFAILURE = 0x00000001 Global Const $PBT_APMBATTERYLOW = 0x0009 Global Const $PBT_APMPOWERSTATUSCHANGE = 0x000A Global Const $PBT_APMOEMEVENT = 0x000B GUICreate("detect WM_POWERBROADCAST") GUISetState() GUIRegisterMsg($WM_POWERBROADCAST, "PowerEvents") $sleeping = False $lidClosed = False While GUIGetMsg() <> -3 WEnd Func PowerEvents($hWnd, $Msg, $wParam, $lParam) Switch $wParam Case $PBT_APMQUERYSTANDBY;perhaps it should be $PBT_APMSUSPEND $lidClosed = True;? $sleeping = True;? Case $PBT_APMRESUMEAUTOMATIC $sleeping = False $lidClosed = False EndSwitch Return $GUI_RUNDEFMSG EndFunc Edit: added comment re $PBT_APMSUSPEND Edited May 25, 2009 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
ken82m Posted May 25, 2009 Share Posted May 25, 2009 I tried something like that, since I just have my machine stay on when I lose the lid. The system still turns of the monitor. That behavior seems unchangeable. Anyway you could use that as an alert and then prevent the suspend or hibernate. Except MS disabled that ability starting in Vista. So the only way to do it seems to be grab the specific lid closed event. Â "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains." Link to comment Share on other sites More sharing options...
motionman95 Posted May 25, 2009 Author Share Posted May 25, 2009 http://www.autoitscript.com/forum/index.ph...&hl=monitorWith that thread, we can tell when the screen has been turned off - but only, I guess, if we can intercept the messages ProgMan gets. Link to comment Share on other sites More sharing options...
motionman95 Posted May 26, 2009 Author Share Posted May 26, 2009 Would these links make it possible to detect whether the monitor is on or off?http://stackoverflow.com/questions/203355/...ndows-on-or-offWM_SYSCOMMAND:http://msdn.microsoft.com/en-us/library/ms646360(VS.85).aspx Link to comment Share on other sites More sharing options...
motionman95 Posted May 29, 2009 Author Share Posted May 29, 2009 I don't like detecting standby because there's no way of knowing whether it's user or windows's initiated. But I guess that means that this can't be done. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now