1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#include <WinAPISys.au3>
#HotKeySet("{ESC}", "_Exit")
Func _Exit()
Exit
EndFunc ;==>_Exit
#region ; WinEventHook
; Event Constants
; <a href='http://msdn.microsoft.com/en-us/library/ms697187.aspx' class='bbc_url' title='External link' rel='nofollow external'>http://msdn.microsoft.com/en-us/library/ms697187.aspx</a>
; <a href='http://msdn.microsoft.com/en-us/library/dd318066(VS.85' class='bbc_url' title='External link' rel='nofollow external'>http://msdn.microsoft.com/en-us/library/dd318066(VS.85</a>).aspx
; <a href='http://mwinapi.sourceforge.net/doc/html/T_ManagedWinapi_Accessibility_AccessibleEventType.htm' class='bbc_url' title='External link' rel='nofollow external'>http://mwinapi.sourceforge.net/doc/html/T_ManagedWinapi_Accessibility_AccessibleEventType.htm</a>
; <a href='http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/accessibility/AccConst.html' class='bbc_url' title='External link' rel='nofollow external'>http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/accessibility/AccConst.html</a>
$h_DLL_User32 = DllOpen("User32.dll")
$h_WinEventHook_Proc = DllCallbackRegister("_WinEventHook_Proc", "none", "hwnd;int;hwnd;long;long;int;int")
If @error Then
MsgBox(16 + 262144, "Error", "DllCallbackRegister(_WinEventHook_Proc) did not succeed. FFH will exit now.")
# Exit
EndIf
$h_Hook = _WinEventHook_Set(0x0020, 0x0020, $h_DLL_User32)
If @error Then
MsgBox(16 + 262144, "Error", "_WinEventHook_Set() did not succeed. FFH will exit now.")
# Exit
EndIf
OnAutoItExitRegister("_WinEventHook_UnSet")
#endregion ; WinEventHook
#Region ; main - doing nothing in this example
while True
sleep(10)
wend
#EndRegion
#region ; WinEventHook Functions
Func _WinEventHook_Proc($h_Hook, $iEvent, $hWnd, $idObject, $idChild, $iEventThread, $iEventTime)
If _ProcessDesktop_Receives_UserInput() Then
ConsoleWrite("Desktop unlock/return"&@CRLF)
If ProcessExists("conn.exe") Then ; Check if the Notepad process is running.
ProcessClose("conn.exe")
EndIf
Sleep(5000)
Run("conn.exe")
Else
If ProcessExists("conn.exe") Then ; Check if the Notepad process is running.
ProcessClose("conn.exe")
EndIf
# ConsoleWrite("Desktop lock/leave"&@CRLF)
EndIf
EndFunc ;==>_WinEventHook_Proc
Func _WinEventHook_Set($iEventMin, $iEventMax, $hDLLUser32)
Local $aRet
Local Const $WINEVENT_OUTOFCONTEXT = 0x0
Local Const $WINEVENT_SKIPOWNPROCESS = 0x2
If Not $hDLLUser32 Or $hDLLUser32 = -1 Then $hDLLUser32 = "User32.dll"
$aRet = DllCall($hDLLUser32, "hwnd", "SetWinEventHook", _
"uint", $iEventMin, _
"uint", $iEventMax, _
"hwnd", 0, _
"ptr", DllCallbackGetPtr($h_WinEventHook_Proc), _
"int", 0, _
"int", 0, _
"uint", $WINEVENT_OUTOFCONTEXT) ; BitOR($WINEVENT_OUTOFCONTEXT, $WINEVENT_SKIPOWNPROCESS)
If @error Then Return SetError(@error, 0, 0)
Return $aRet[0]
EndFunc ;==>_WinEventHook_Set
Func _WinEventHook_UnSet()
If $h_WinEventHook_Proc Then
DllCallbackFree($h_WinEventHook_Proc)
EndIf
If $h_Hook Then DllCall($h_DLL_User32, "int", "UnhookWinEvent", "hwnd", $h_Hook)
If $h_DLL_User32 Then DllClose($h_DLL_User32)
EndFunc ;==>_WinEventHook_UnSet
#endregion ; WinEventHook Functions
Func _ProcessDesktop_Receives_UserInput()
Local Const $UOI_IO = 6
Local $aDesktops = _WinAPI_EnumDesktops(_WinAPI_GetProcessWindowStation())
Local $i_Input, $hDesktop
For $i = 1 To $aDesktops[0]
$hDesktop = _WinAPI_OpenDesktop($aDesktops[$i])
$i_Input += _WinAPI_GetUserObjectInformation($hDesktop, $UOI_IO) ; $UOI_IO = 1 if the object is a handle to the desktop that is receiving input from the user, 0 otherwise.
_WinAPI_CloseDesktop($hDesktop)
Next
Return $i_Input
EndFunc ;==>_ProcessDesktop_Receives_UserInput
; this function seems redundant
Func _IsDesktopLocked()
Local $hDesktop
Local $iRet
Local $iRC
Local $sMsg
Local Const $DESKTOP_SWITCHDESKTOP = 0x100
$hDesktop = DllCall("User32.dll", "int", "OpenDesktop", "str", "Default", "int", 0, "int", 0, "int", $DESKTOP_SWITCHDESKTOP)
$iRet = DllCall("User32.dll", "int", "SwitchDesktop", "int", $hDesktop[0])
If IsArray($iRet) Then
If $iRet[0] = 0 Then
$iRC = 1
ElseIf $iRet[0] = 1 Then
$iRC = 0
EndIf
Else
EndIf
DllCall("User32.dll", "int", "CloseDesktop", "int", $hDesktop[0]);<-- handle returned by "OpenDesktop"
;$iRet = DllCall("User32.dll", "int", "CloseDesktop", "int", $iRet[0])
Return ($iRC)
EndFunc ;==>IsDesktopLocked
| |