-
Notifications
You must be signed in to change notification settings - Fork 0
/
lockedLauncher.au3
executable file
·87 lines (68 loc) · 2.32 KB
/
lockedLauncher.au3
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
#RequireAdmin
#include <AutoItConstants.au3>
#include <File.au3>
#include <WinAPIFiles.au3>
#include <Misc.au3>
_Singleton(@ScriptName)
Global $unlockOnWindow
Global $unlockOnWindowTimeout
Global $unlockOnWindowDelay
Global $unlockAfter
Global $audibleLockStatusChange
Global $iLaunchedPid
Main()
Func Main()
Init()
If Not IsAdmin() Then LogMessage("working without admin rights; lock logic will not work")
LockInput()
DoLaunch()
; Unlock behavior: Window based OR time based
If Not $unlockOnWindow = "" Then
LogMessage("unlock behavior: on target window")
$hWin = WinWaitActive($unlockOnWindow, "", $unlockOnWindowTimeout)
if $hWin<>0 Then
LogMessage("target window found!")
Sleep($unlockOnWindowDelay * 1000)
EndIf
Else
LogMessage("unlock behavior: fixed delay")
Sleep($unlockAfter * 1000)
EndIf
UnLockInput()
ProcessWaitClose($iLaunchedPid)
LogMessage("end")
EndFunc
; Init parameters
Func Init()
; unlock on window
$unlockOnWindow = IniRead(@ScriptDir & "\lockedLauncher.ini", "General", "unlockOnWindow", "")
; unlock on window delay
$unlockOnWindowDelay = Number(IniRead(@ScriptDir & "\lockedLauncher.ini", "General", "unlockOnWindowDelay", "5"))
; unlock on window timeout
$unlockOnWindowTimeout = Number(IniRead(@ScriptDir & "\lockedLauncher.ini", "General", "unlockOnWindowTimeout", "50"))
; fixed unlock delay
$unlockAfter = Number(IniRead(@ScriptDir & "\lockedLauncher.ini", "General", "unlockAfter", "15"))
; audible lock/unlock
$audibleLockStatusChange = IniRead(@ScriptDir & "\lockedLauncher.ini", "General", "audibleLockStatusChange", "False")
EndFunc
; Disable user input (mouse and keyboard)
Func LockInput()
$iBlockResult = BlockInput($BI_DISABLE)
if $audibleLockStatusChange = "True" Then Beep(500, 500)
LogMessage("input disabled: " & $iBlockResult)
EndFunc
; Enable user input (mouse and keyboard)
Func UnLockInput()
$iBlockResult = BlockInput($BI_ENABLE)
if $audibleLockStatusChange = "True" Then Beep(1000, 500)
LogMessage("input enabled: " & $iBlockResult)
EndFunc
; Launch logic
Func DoLaunch()
Log("invoke: " & $CmdLineRaw)
$iLaunchedPid = Run($CmdLineRaw)
LogMessage("invoked, pid: " & $iLaunchedPid)
EndFunc
Func LogMessage($logMessage)
_FileWriteLog(@ScriptDir & "\lockedLauncher.log", $logMessage)
EndFunc