Jump to content

Do action just before screen lock windows 10


Recommended Posts

Hi,

I have a stopwatch measuring my screen time. I need a script which will pause (send("^1")) my stopwatch when i lock my sceen.

All scripts I found here can not understand that screen was locked until it is unlocked.

Here they are, bad examples:

Func _IsLocked() ; Both functions can't understand that screen is locked now, script only can see that screen WAS locked only after PC is UNLOCKED...
    Local $fIsLocked = False
    Local Const $hDesktop = _WinAPI_OpenDesktop('Default', $DESKTOP_SWITCHDESKTOP)
    If @error = 0 Then
        $fIsLocked = Not _WinAPI_SwitchDesktop($hDesktop)
        _WinAPI_CloseDesktop($hDesktop)
    EndIf
    Return $fIsLocked
 EndFunc   ;==>_IsLocked

Func _IsWorkstationLocked()

    Local $Result = False

    $hDesktop = DllCall('user32.dll', 'hwnd', 'OpenDesktop', 'str', 'Default', 'int', 0, 'int', 0, 'int', $DESKTOP_SWITCHDESKTOP)
    If Not @error Then
        $Result = DllCall('user32.dll', 'int', 'SwitchDesktop', 'hwnd', $hDesktop[0])
        $Result = Not $Result[0]
        DllCall('user32.dll', 'int', 'CloseDesktop', 'hwnd', $hDesktop[0])
    EndIf
    Return $Result
EndFunc   ;==>_IsWorkstationLocked

Maybe someone has an Idea how to detect screen locking action, and do something just right in time of locking?

Link to comment
Share on other sites

Maybe that can help you

You can try to first get the Power Scheme GUID that is activated and then read Registry and get the value in seconds that inside the key "Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\PowerSettings\7516b95f-f776-4464-8c53-06167f40cc99\8EC4B3A5-6868-48c2-BE75-4F3044BE88A7\DefaultPowerSchemeValues\here go the Power Scheme GUID that is activated" and then check when mouse is not moving and start doing a countdown if mouse move it restart checking if mouse is not moving.

Link to comment
Share on other sites

ex19a_events.au3 in IUIAutomation thread of examples can help you out

and before you ask it see FAQ 31

and no you cannot catch ctrl+alt+del key in a normal way (you can google why)

on my system W10 when i do ctrl+alt+delete and choose lock screen I get below event

$iEventId    = 20016    Title     = Schakelen tussen taken  Class     = MultitaskingViewFrame   Ctrl type = 50032   Ctrl name = venster Value     =     Handle    = 00181C8E    
$iEventId    = 20016    Title     = Windows-standaardvergrendelingsscherm   Class     = Windows.UI.Core.CoreWindow  Ctrl type = 50032   Ctrl name = venster Value     =     Handle    = 00010278    
$iEventId    = 20017    Title     = Windows-standaardvergrendelingsscherm   Class     = Windows.UI.Core.CoreWindow  Ctrl type = 50032   Ctrl name = venster Value     =     Handle

when i do ctrl+alt+delete I get taskmanager window event

$iEventId    = 20016    Title     = Schakelen tussen taken  Class     = MultitaskingViewFrame   Ctrl type = 50032   Ctrl name = venster Value     =     Handle    = 00181C8E    
$iEventId    = 20016    Title     = Windows-standaardvergrendelingsscherm   Class     = Windows.UI.Core.CoreWindow  Ctrl type = 50032   Ctrl name = venster Value     =     Handle    = 00010278    
$iEventId    = 20017    Title     = Windows-standaardvergrendelingsscherm   Class     = Windows.UI.Core.CoreWindow  Ctrl type = 50032   Ctrl name = venster Value     =     Handle

when i do ctrl+alt+delete change password I get NO EVENT

but maybe more events can be caught as in base example it only filters on events with visible windows

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