Jump to content

Can this be done in AutoIt?


Recommended Posts

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 by motionman95
Link to comment
Share on other sites

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.

#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 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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...