Skip to content

Commit 842b829

Browse files
committed
replaced WinActivate with much more reliable PostMessage, added debugging options
1 parent 21c2a6f commit 842b829

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

UAC-Focus.ahk

+40-27
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
( LTrim RTrim0 Join
6969
Startup parameters:
7070
`n`n
71-
71+
7272
-notify
7373
`n
7474
Start with ""Notify on focus"" enabled by default.
@@ -80,7 +80,7 @@
8080
`n
8181
Start with ""Notify always"" enabled by default.
8282
`n
83-
Same as above, but also display notification if the UAC window
83+
Same as above, but also display notification if the UAC window
8484
pops up already focused by the OS.
8585
`n`n
8686

@@ -147,10 +147,15 @@
147147

148148
; Tray menu
149149
Menu, Tray, Click, 2
150-
Menu, Tray, NoStandard ; Standard/NoStandard = debugging / normal
151-
Menu, Tray, Add, &Debug, debug_window
150+
Menu, Tray, NoStandard
151+
152+
; Enable for debug menu
153+
; Menu, Tray, Add, &Debug, debug
154+
; Menu, Tray, Add
155+
152156
Menu, Tray, Add, &About, about_box
153157
Menu, Tray, Default, &About
158+
; Menu, Tray, Default, &Debug
154159

155160
; Letter «i» in blue circle icon
156161
Menu, Tray, Icon, &About, %A_Windir%\system32\SHELL32.dll, 278
@@ -163,7 +168,7 @@
163168
Menu, OptionID, Add
164169
Menu, OptionID, Add, Beep on focus, notify_toggle
165170
Menu, Tray, Add, &Notify, :OptionID
166-
171+
167172
; White balloon tip with «i» icon
168173
; Menu, Tray, Icon, &Notify, %A_Windir%\system32\SHELL32.dll, 222
169174

@@ -177,11 +182,11 @@
177182

178183
Menu, Tray, Add
179184
Menu, Tray, Add, &Open file location, open_Location
180-
185+
181186
; Document with loupe icon
182187
Menu, Tray, Icon, &Open file location, %A_Windir%\system32\SHELL32.dll, 56
183188
Menu, Tray, Add, &Help, help_box
184-
189+
185190
; «?» mark in blue circle icon
186191
Menu, Tray, Icon, &Help, %A_Windir%\system32\SHELL32.dll, 24
187192
Menu, Tray, Add
@@ -209,9 +214,13 @@ OnMessage( MsgNum, "ShellMessage" )
209214

210215
if (InStr(class, "Credential Dialog Xaml Host") and InStr(process, "consent.exe"))
211216
{
212-
; Temporarily change to 'if not' for easier debugging
213217
if WinActive (ahk_id lParam)
214218
{
219+
loop, 4
220+
{
221+
sleep 75
222+
PostMessage, WM_SYSCOMMAND := 0x0112, SC_HOTKEY := 0xF150, %lParam%,,
223+
}
215224

216225
if (beep = "All")
217226
SoundBeep, , 100
@@ -221,28 +230,32 @@ OnMessage( MsgNum, "ShellMessage" )
221230
}
222231
else
223232
{
224-
WinActivate (ahk_id lParam)
233+
loop, 4
234+
{
235+
sleep 75
236+
PostMessage, WM_SYSCOMMAND := 0x0112, SC_HOTKEY := 0xF150, %lParam%,,
237+
}
238+
225239
Gosub activation_followup
226240
}
227-
228-
; If enabled, stops working with multiple windows:
229-
; WinWaitClose, ahk_id %lParam%
230241
}
231242
}
232243
}
233244

234245

235246
; ================================================================================================
236247
; Functions & subroutines
237-
exit()
248+
; Esc::Reload
249+
250+
debug()
238251
{
239-
ExitApp
252+
ListVars
253+
Pause On
240254
}
241255

242-
debug_window()
256+
exit()
243257
{
244-
ListVars
245-
pause, on
258+
ExitApp
246259
}
247260

248261
open_Location()
@@ -263,22 +276,22 @@ OnMessage( MsgNum, "ShellMessage" )
263276
if FileExist(tray_icon)
264277
Menu, Tray, Icon, %tray_icon%
265278
return
266-
267-
279+
280+
268281
; Subroutine
269282
/*
270283
Additional icons to consider:
271-
284+
272285
Green shield with checkmark icon
273286
Menu, Tray, Icon, %A_Windir%\system32\imageres.dll, 102
274-
287+
275288
Blue circled arrows icon
276289
Menu, Tray, Icon, %A_Windir%\System32\shell32.dll, 239
277-
290+
278291
Green checkmark icon
279292
Menu, Tray, Icon, %A_Windir%\System32\shell32.dll, 297
280293
*/
281-
294+
282295
do_flash_tray_icon:
283296
SetTimer, do_flash_tray_icon, Off
284297
Menu, Tray, Icon, %tray_icon_flashed% ; Use embedded icon data
@@ -499,16 +512,16 @@ icon_green(NewHandle := False)
499512
500513
If
501514
( RTrim0 Join
502-
!DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt",
515+
!DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt",
503516
0, "UInt", 0x01, "Ptr", 0, "UIntP", DecLen, "Ptr", 0, "Ptr", 0)
504517
)
505518
Return False
506-
519+
507520
VarSetCapacity(Dec, DecLen, 0)
508521

509522
If
510523
( RTrim0 Join
511-
!DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt",
524+
!DllCall("Crypt32.dll\CryptStringToBinary", "Ptr", &B64, "UInt",
512525
0, "UInt", 0x01, "Ptr", &Dec, "UIntP", DecLen, "Ptr", 0, "Ptr", 0)
513526
)
514527
Return False
@@ -517,7 +530,7 @@ icon_green(NewHandle := False)
517530
; (JPEG/PNG/GIF) to hBITMAP?" by SKAN
518531
; -> http://www.autohotkey.com/board/topic/21213-how-to-convert-image-
519532
; data-jpegpnggif-to-hbitmap/?p=139257
520-
533+
521534
hData := DllCall("Kernel32.dll\GlobalAlloc", "UInt", 2, "UPtr", DecLen, "UPtr")
522535
pData := DllCall("Kernel32.dll\GlobalLock", "Ptr", hData, "UPtr")
523536
DllCall("Kernel32.dll\RtlMoveMemory", "Ptr", pData, "Ptr", &Dec, "UPtr", DecLen)

0 commit comments

Comments
 (0)