Bonjour à tous,
après une longue pause dans le développement d'AutoIt, je me tourne vers vous afin de vous d'exposer l'un de mes petits soucis.
Dans le cadre d'un petit projet j'ai fabriquer un pad avec quelques boutons et un potentiomètre afin de créer des macros et gérer le son. Mais j'aimerais rajouter un petit capteur de présence pour qu'il puisse réveiller les écrans si ils sont en veilles.
Je souhaiterais donc un petit script pour détecter la mise en veille d'un ou des écrans (WINDOWS 10). On peut modifier les paramètres dans panneau de configuration / système / alimentation et mise en veille -> Ecran (En cas de branchement sur le secteur, éteindre après ...)
Dans mon cas c'est un desktop donc je n'ai pas les options "batterie".
Merci
[R] La détection d'extinction d'un écran
Règles du forum
- Merci de consulter la section "Règles du forum" et plus particulièrement "Règles et Mentions Légales du site autoitscript.fr" avant d'écrire un message.
[R] La détection d'extinction d'un écran
Modifié en dernier par Zippo le lun. 16 mai 2016 16:00, modifié 1 fois.
- TommyDDR
- Modérateur

- Messages : 2109
- Enregistré le : mar. 22 juil. 2008 21:55
- Localisation : Nantes
- Status : Hors ligne
Re: [..] La détection d'extinction d'un écran
Si vous trouvez comment récupérer le temps configuré pour l'extinction de l'écran, vous pouvez le comparer à _Timer_GetIdleTime() qui vous retournera le temps écoulé depuis la dernière action utilisateur.
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
Re: [..] La détection d'extinction d'un écran
Excellemment ! C'est très intéressent. En effet ce code n'est pas portable, dans le sens où il a été codé pour mon utilisation personnelle. Donc je connais le temps attribué. Je vais tester sa
!
Merci TommyDDR
Merci TommyDDR
Re: [..] La détection d'extinction d'un écran
Je clos le sujet. J ai pu effectivement solutionner mon problème avec _Timer_GetIdleTime et une simple condition.
Je te remercie une seconde fois TommyDDR
Je te remercie une seconde fois TommyDDR
- orax
- Modérateur

- Messages : 1479
- Enregistré le : lun. 23 mars 2009 04:50
- Localisation : ::1
- Status : Hors ligne
Re: [R] La détection d'extinction d'un écran
Autre solution, avec WM_POWERBROADCAST :
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
Global Const $GUID_CONSOLE_DISPLAY_STATE = "{6fe69556-704a-47a0-8f24-c28d936fda47}"
Global Const $PBT_APMPOWERSTATUSCHANGE = 0xA ; Power status has changed.
Global Const $PBT_APMRESUMEAUTOMATIC = 0x12 ; Operation is resuming automatically from a low-power state. This message is sent every time the system resumes.
Global Const $PBT_APMRESUMESUSPEND = 0x7 ; Operation is resuming from a low-power state. This message is sent after PBT_APMRESUMEAUTOMATIC if the resume is triggered by user input, such as pressing a key.
Global Const $PBT_APMSUSPEND = 0x4 ; System is suspending operation.
Global Const $PBT_POWERSETTINGCHANGE = 0x8013 ; A power setting change event has been received.
Global Const $tagPOWERBROADCAST_SETTING = $tagGUID & ";dword DataLength;dword Data;endstruct"
$hWnd = GUICreate("")
GUIRegisterMsg($WM_POWERBROADCAST, "WM_POWERBROADCAST")
;~ _WinAPI_RegisterPowerSettingNotification($hWnd, $GUID_MONITOR_POWER_ON) ; Windows Vista, 7, Serveur 2008 R2 et Serveur 2008
_WinAPI_RegisterPowerSettingNotification($hWnd, $GUID_CONSOLE_DISPLAY_STATE) ; à partir de Windows 8, Serveur 2012
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
Func WM_POWERBROADCAST($hWnd, $iMsg, $wParam, $lParam)
$tSetting = DllStructCreate($tagPOWERBROADCAST_SETTING, $lParam)
$iData = DllStructGetData($tSetting, "Data")
; 0x0 - The display is off.
; 0x1 - The display is on.
; 0x2 - The display is dimmed.
ConsoleWrite($iData & @CRLF)
EndFunc ;==>WM_POWERBROADCAST
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
Global Const $GUID_CONSOLE_DISPLAY_STATE = "{6fe69556-704a-47a0-8f24-c28d936fda47}"
Global Const $PBT_APMPOWERSTATUSCHANGE = 0xA ; Power status has changed.
Global Const $PBT_APMRESUMEAUTOMATIC = 0x12 ; Operation is resuming automatically from a low-power state. This message is sent every time the system resumes.
Global Const $PBT_APMRESUMESUSPEND = 0x7 ; Operation is resuming from a low-power state. This message is sent after PBT_APMRESUMEAUTOMATIC if the resume is triggered by user input, such as pressing a key.
Global Const $PBT_APMSUSPEND = 0x4 ; System is suspending operation.
Global Const $PBT_POWERSETTINGCHANGE = 0x8013 ; A power setting change event has been received.
Global Const $tagPOWERBROADCAST_SETTING = $tagGUID & ";dword DataLength;dword Data;endstruct"
$hWnd = GUICreate("")
GUIRegisterMsg($WM_POWERBROADCAST, "WM_POWERBROADCAST")
;~ _WinAPI_RegisterPowerSettingNotification($hWnd, $GUID_MONITOR_POWER_ON) ; Windows Vista, 7, Serveur 2008 R2 et Serveur 2008
_WinAPI_RegisterPowerSettingNotification($hWnd, $GUID_CONSOLE_DISPLAY_STATE) ; à partir de Windows 8, Serveur 2012
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
Func WM_POWERBROADCAST($hWnd, $iMsg, $wParam, $lParam)
$tSetting = DllStructCreate($tagPOWERBROADCAST_SETTING, $lParam)
$iData = DllStructGetData($tSetting, "Data")
; 0x0 - The display is off.
; 0x1 - The display is on.
; 0x2 - The display is dimmed.
ConsoleWrite($iData & @CRLF)
EndFunc ;==>WM_POWERBROADCAST
De petits détails peuvent faire toute la différence. — Quand la boule de neige commence à rouler… poussez-la. (Columbo)

