Sign in to follow this  
Followers 0
motionman95

Can this be done in AutoIt?

9 posts in this topic

#1 ·  Posted (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 by motionman95

Share this post


Link to post
Share on other sites



Bump


Share this post


Link to post
Share on other sites

The screen is turned off when the lid is closed?

Share this post


Link to post
Share on other sites

I'm not sure - I think so...


Share this post


Link to post
Share on other sites

#5 ·  Posted (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.

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

Share this post


Link to post
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.


My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "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."

Share this post


Link to post
Share on other sites

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. :)


Share this post


Link to post
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
Sign in to follow this  
Followers 0