 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Serenity
Joined: 07 Nov 2004 Posts: 1271
|
Posted: Thu Sep 11, 2008 4:56 pm Post subject: [tool] WinEventHook Messages |
|
|
WinEventHook Messages displays messages received via SetWinEventHook. Majkinetor showed us how to use RegisterCallback to receive these messages. I wrote this to catch windows that couldn't be caught by ShellHook method. As with ShellHook Messages there is a message filter. I'm really glad I wrote it now, the message stream updates pretty quickly.
Hooking a particular process/Hooking all processes
WinEventHook Messages hooks all processes by default. You can hook a particular process only by right-clicking in the list and checking "Receive events for this process only" in the popup menu. To restore the hook to all processes, right-click and uncheck.
Message Filter
When checked, these messages will not show.
Hotkeys
Ctrl+C to copy selected line to clipboard
C to clear list
P to pause
R to reload
X to exit
Version History
2008/09/13 v0.3 released
- Replaced DecToHex function with commands to hopefully speed things up a little.
- Some events are received in decimal format, these are now converted to hexadecimal.
- Added option to exclude messages generated by script process. Default is exclude.
- Added hotkey to copy selected line to clipboard.
- Added option to hook a process only. Defaults to hook all processes.
2008/09/12 v0.2 released
- Fixed bug causing some messages to not display.
- Added EVENT_SYSTEM_SOUND message.
2008/09/11 v0.1 released
Further reading
Event Constants
| Code: | ; WinEventHook Messages v0.3 by Serenity
; http://www.autohotkey.com/forum/viewtopic.php?t=35659
#SingleInstance Force
#Persistent
SetBatchLines,-1
; Process, Priority,, High
ExcludeScriptMessages = 1 ; 0 to include
Title := "WinEventHook Messages", Filters := "", Pause := 0
FilterMenu(), Gui()
ahk := WinExist(), WM_VSCROLL := 0x115, SB_BOTTOM := 7
HookProcAdr := RegisterCallback( "HookProc", "F" )
dwFlags := ( ExcludeScriptMessages = 1 ? 0x1 : 0x0 )
hWinEventHook := SetWinEventHook( 0x1, 0x17, 0, HookProcAdr, 0, 0, 0 )
Return
FilterMenu()
{
Global FilterList
Menu, Filter, Add, Filter &All, FilterAll
Menu, Filter, Add, Filter &None, FilterNone
Menu, Filter, Add
FilterList = SOUND,ALERT,FOREGROUND,MENUSTART,MENUEND,MENUPOPUPSTART,MENUPOPUPEND
,CAPTURESTART,CAPTUREEND,MOVESIZESTART,MOVESIZEEND,CONTEXTHELPSTART
,CONTEXTHELPEND,DRAGDROPSTART,DRAGDROPEND,DIALOGSTART,DIALOGEND,SCROLLINGSTART
,SCROLLINGEND,SWITCHSTART,SWITCHEND,MINIMIZESTART,MINIMIZEEND
Loop, Parse, FilterList, `,
{
If A_Loopfield
Menu, Filter, Add, %A_Loopfield%, SetFilter
}
Menu, FilterMenu, Add, Message &Filter, :Filter
Gui, Menu, FilterMenu
}
Gui()
{
Global
Gui, +LastFound +AlwaysOnTop +Resize ; +ToolWindow
Gui, Margin, 0, 0
Gui, Font, s8, Microsoft Sans Serif
Gui, Color,, DEDEDE
Gui, Add, ListView, w600 r10 vData +Grid +NoSort, Hwnd|idObject|idChild|Title|Class|Event|Message
LV_ModifyCol( 1, 60 ), LV_ModifyCol( 2, 40), LV_ModifyCol( 3, 40)
LV_ModifyCol( 4, 100 ), LV_ModifyCol( 5, 100 ), LV_ModifyCol( 7, 190 )
Gui, Show,, %Title%
}
HookProc( hWinEventHook, Event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime )
{
Global Pause,WM_VSCROLL,SB_BOTTOM,ahk,Filters
SetFormat, Integer, Dec
Event += 0
if Event = 1
Message = EVENT_SYSTEM_SOUND
else if Event = 2
Message = EVENT_SYSTEM_ALERT
else if Event = 3
Message = EVENT_SYSTEM_FOREGROUND
else if Event = 4
Message = EVENT_SYSTEM_MENUSTART
else if Event = 5
Message = EVENT_SYSTEM_MENUEND
else if Event = 6
Message = EVENT_SYSTEM_MENUPOPUPSTART
else if Event = 7
Message = EVENT_SYSTEM_MENUPOPUPEND
else if Event = 8
Message = EVENT_SYSTEM_CAPTURESTART
else if Event = 9
Message = EVENT_SYSTEM_CAPTUREEND
else if Event = 10
Message = EVENT_SYSTEM_MOVESIZESTART
else if Event = 11
Message = EVENT_SYSTEM_MOVESIZEEND
else if Event = 12
Message = EVENT_SYSTEM_CONTEXTHELPSTART
else if Event = 13
Message = EVENT_SYSTEM_CONTEXTHELPEND
else if Event = 14
Message = EVENT_SYSTEM_DRAGDROPSTART
else if Event = 15
Message = EVENT_SYSTEM_DRAGDROPEND
else if Event = 16
Message = EVENT_SYSTEM_DIALOGSTART
else if Event = 17
Message = EVENT_SYSTEM_DIALOGEND
else if Event = 18
Message = EVENT_SYSTEM_SCROLLINGSTART
else if Event = 19
Message = EVENT_SYSTEM_SCROLLINGEND
else if Event = 20
Message = EVENT_SYSTEM_SWITCHSTART
else if Event = 21
Message = EVENT_SYSTEM_SWITCHEND
else if Event = 22
Message = EVENT_SYSTEM_MINIMIZESTART
else if Event = 23
Message = EVENT_SYSTEM_MINIMIZEEND
Sleep, 50 ; give a little time for WinGetTitle/WinGetActiveTitle functions, otherwise they return blank
EventHex := Event
SetFormat, Integer, Hex
EventHex += 0, hWnd += 0, idObject += 0, idChild += 0
If Event not in %Filters%
{
If ( Pause = 0 )
{
LV_Add( "", hWnd, idObject, idChild, WinGetTitle(hWnd), WinGetClass(hWnd), EventHex, Message )
}
SendMessage, WM_VSCROLL, SB_BOTTOM, 0, SysListView321, ahk_id %ahk%
}
}
SetFilter:
Menu, Filter, ToggleCheck, %A_ThisMenuItem%
Loop, Parse, FilterList, `,
{
If ( A_ThisMenuItem = A_Loopfield )
{
If A_Index in %Filters% ; remove from filter
{
Filter := A_Index
Loop, Parse, Filters, `,
{
If ( A_Loopfield != Filter )
NewFilters .= A_Loopfield . ( A_Loopfield != "" ? "`," : "" )
}
Filters := NewFilters, NewFilters := ""
}
Else ; add to filter
{
Filters .= A_Index . ","
}
}
}
Return
FilterAll:
Filters =
Loop, Parse, FilterList, `,
{
Menu, Filter, Check, %A_Loopfield%
Filters .= A_Index . ( A_Index != 23 ? "," : "" )
}
Return
FilterNone:
Loop, Parse, FilterList, `,
{
Menu, Filter, UnCheck, %A_Loopfield%
Filters =
}
Return
WinGetTitle( hwnd )
{
WinGetTitle, wtitle, ahk_id %hwnd%
Return wtitle
}
WinGetClass( hwnd )
{
WinGetClass, wclass, ahk_id %hwnd%
Return wclass
}
SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags)
{
DllCall("CoInitialize", Uint, 0)
return DllCall("SetWinEventHook"
, Uint,eventMin
, Uint,eventMax
, Uint,hmodWinEventProc
, Uint,lpfnWinEventProc
, Uint,idProcess
, Uint,idThread
, Uint,dwFlags)
}
NewHook()
{
Global
If HookSelected = 1
{
LV_GetText( SelHwnd, LV_GetNext(0, "Focused") )
WinGet, idProcess, PID, ahk_id %SelHwnd%
If idProcess =
{
Menu, Ctx, ToggleCheck, &Receive events from this process only
HookSelected := !HookSelected
Return
}
}
Else
{
idProcess = 0 ; hook all
}
UnhookWinEvent()
HookProcAdr := RegisterCallback( "HookProc", "F" ) ; new hook
hWinEventHook := SetWinEventHook( 0x1, 0x17, 0, HookProcAdr, idProcess, 0, dwFlags )
}
UnhookWinEvent()
{
Global
DllCall( "UnhookWinEvent", Uint,hWinEventHook )
DllCall( "GlobalFree", UInt,&HookProcAdr ) ; free up allocated memory for RegisterCallback
}
GuiContextMenu:
Menu, Ctx, Add, &Receive events from this process only, HookMode
Menu, Ctx, Show
Return
HookMode:
Menu, Ctx, ToggleCheck, &Receive events from this process only
HookSelected := !HookSelected
NewHook()
Return
GuiSize:
GuiControl, Move, Data, w%A_GuiWidth% h%A_GuiHeight%
SendMessage, WM_VSCROLL, SB_BOTTOM, 0, SysListView321, ahk_id %ahk%
Return
GuiClose:
GuiEscape:
ExitApp
Return
#IfWinActive WinEventHook Messages
C::LV_Delete()
P::
Pause :=! Pause, WinTitle := ( Pause = 0 ? Title : Title . " (Paused)" )
WinSetTitle %WinTitle%
Return
R::Reload
X::ExitApp
^C::
Clipboard =
Loop, % LV_GetCount("Col")
{
LV_GetText( lv%A_Index%, LV_GetNext(0, "Focused"), A_Index )
Clipboard .= lv%A_Index% . ( A_Index != LV_GetCount("Col") ? "|" : "" )
}
Return
#IfWinActive |
| Code: | ; Event Constants
EVENT_SYSTEM_SOUND = 0x1
EVENT_SYSTEM_ALERT = 0x2
EVENT_SYSTEM_FOREGROUND = 0x3
EVENT_SYSTEM_MENUSTART = 0x4
EVENT_SYSTEM_MENUEND = 0x5
EVENT_SYSTEM_MENUPOPUPSTART = 0x6
EVENT_SYSTEM_MENUPOPUPEND = 0x7
EVENT_SYSTEM_CAPTURESTART = 0x8
EVENT_SYSTEM_CAPTUREEND = 0x9
EVENT_SYSTEM_MOVESIZESTART = 0xa
EVENT_SYSTEM_MOVESIZEEND = 0xb
EVENT_SYSTEM_CONTEXTHELPSTART = 0xc
EVENT_SYSTEM_CONTEXTHELPEND = 0xd
EVENT_SYSTEM_DRAGDROPSTART = 0xe
EVENT_SYSTEM_DRAGDROPEND = 0xf
EVENT_SYSTEM_DIALOGSTART = 0x10
EVENT_SYSTEM_DIALOGEND = 0x11
EVENT_SYSTEM_SCROLLINGSTART = 0x12
EVENT_SYSTEM_SCROLLINGEND = 0x13
EVENT_SYSTEM_SWITCHSTART = 0x14
EVENT_SYSTEM_SWITCHEND = 0x15
EVENT_SYSTEM_MINIMIZESTART = 0x16
EVENT_SYSTEM_MINIMIZEEND = 0x17
|
_________________ "Anything worth doing is worth doing slowly." - Mae West

Last edited by Serenity on Fri Sep 19, 2008 1:14 am; edited 7 times in total |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 3700 Location: Louisville KY USA
|
Posted: Thu Sep 11, 2008 5:42 pm Post subject: |
|
|
this is also a very very nice tool ill use this and [tool] ShellHook Messages alot _________________
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed; |
|
| Back to top |
|
 |
Guest
|
Posted: Thu Sep 11, 2008 11:29 pm Post subject: |
|
|
Wow thank you very much
You gotta be a genious  |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1271
|
Posted: Fri Sep 12, 2008 12:37 am Post subject: |
|
|
Aw, thank you both. Guest, that's sweet of you to say.
I found some bugs and fixed them in v0.2. See first post for details. _________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1271
|
Posted: Fri Sep 12, 2008 11:45 pm Post subject: |
|
|
v0.3 released:
- Replaced DecToHex function with commands to hopefully speed things up a little.
- Some events are received in decimal format, these are now converted to hexadecimal.
- Added option to exclude messages generated by script process. Default is exclude.
- Added hotkey to copy selected line to clipboard.
- Added option to hook a process only. Defaults to hook all processes.
_________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1271
|
Posted: Thu Dec 04, 2008 2:16 pm Post subject: |
|
|
Here's an example of a popup blocker using Notepad. The first two parameters in the call to SetWinEventHook() are set to 0x3 to only receive EVENT_SYSTEM_FOREGROUND messages.
| Code: | #SingleInstance Force
#Persistent
SetBatchLines,-1
HookProcAdr := RegisterCallback( "HookProc", "F" )
hWinEventHook := SetWinEventHook( 0x3, 0x3, 0, HookProcAdr, 0, 0, 0 )
OnExit, HandleExit
Return
HookProc( hWinEventHook, Event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime )
{
if Event ; EVENT_SYSTEM_FOREGROUND = 0x3
{
WinGetClass, class, ahk_id %hWnd%
If class = Notepad
WinClose, ahk_class Notepad
}
}
SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags)
{
DllCall("CoInitialize", Uint, 0)
return DllCall("SetWinEventHook"
, Uint,eventMin
, Uint,eventMax
, Uint,hmodWinEventProc
, Uint,lpfnWinEventProc
, Uint,idProcess
, Uint,idThread
, Uint,dwFlags)
}
UnhookWinEvent()
{
Global
DllCall( "UnhookWinEvent", Uint,hWinEventHook )
DllCall( "GlobalFree", UInt,&HookProcAdr ) ; free up allocated memory for RegisterCallback
}
HandleExit:
UnhookWinEvent()
ExitApp
Return |
_________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
DeWild1
Joined: 30 Apr 2006 Posts: 358 Location: Shigle Springs
|
Posted: Thu Dec 11, 2008 3:14 pm Post subject: |
|
|
Thank you for your PM with the same example.. (I post here as well for it may help others)
I have spent much time playing with it and I found it to be very efficient and light on the CPU.
Questions:
1. I can not get it to work at all for FireFox or IE. For normal windows, it works much better than SHELLHOOK but SHELLHOOK did work every now and then for IE and FF...
I may have to settle for image search or something like this,,,
| Code: |
#Persistent
settitlematchmode, 1 ;starts with......
WinTitle = bla bla bla ;some IE window
SetTimer, Checkwindow, 50
return
Checkwindow:
If WinActive( WinTitle )
WinClose ;or whatever..
Return
|
2. I know this mainly works for window messages, and this question will make me seem dumber than I already look, (but I have NO shame ), is there anyway to sense a new process being started? _________________ CPULOCK.com
virusSWAT.com
Computer Repair Computer Service.com
911PCFIX.com |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Dec 12, 2008 2:25 am Post subject: |
|
|
| Serenity wrote: | Here's an example of a popup blocker using Notepad. The first two parameters in the call to SetWinEventHook() are set to 0x3 to only receive EVENT_SYSTEM_FOREGROUND messages.
| Code: | #SingleInstance Force
#Persistent
SetBatchLines,-1
HookProcAdr := RegisterCallback( "HookProc", "F" )
hWinEventHook := SetWinEventHook( 0x3, 0x3, 0, HookProcAdr, 0, 0, 0 )
OnExit, HandleExit
Return
HookProc( hWinEventHook, Event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime )
{
if Event ; EVENT_SYSTEM_FOREGROUND = 0x3
{
WinGetClass, class, ahk_id %hWnd%
If class = Notepad
WinClose, ahk_class Notepad
}
}
SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags)
{
DllCall("CoInitialize", Uint, 0)
return DllCall("SetWinEventHook"
, Uint,eventMin
, Uint,eventMax
, Uint,hmodWinEventProc
, Uint,lpfnWinEventProc
, Uint,idProcess
, Uint,idThread
, Uint,dwFlags)
}
UnhookWinEvent()
{
Global
DllCall( "UnhookWinEvent", Uint,hWinEventHook )
DllCall( "GlobalFree", UInt,&HookProcAdr ) ; free up allocated memory for RegisterCallback
}
HandleExit:
UnhookWinEvent()
ExitApp
Return |
|
Serenity, this works swell in XP, but can you tell why this may not work in Vista?, what is wrong  |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1271
|
Posted: Fri Dec 12, 2008 5:43 pm Post subject: |
|
|
| DeWild1 wrote: | | I can not get it to work at all for FireFox or IE. |
It works for me on 2k with Explorer messages (Confirm File Delete etc.) and Firefox. Try this:
| Code: | #SingleInstance Force
#Persistent
SetBatchLines,-1
HookProcAdr := RegisterCallback( "HookProc", "F" )
hWinEventHook := SetWinEventHook( 0x3, 0x3, 0, HookProcAdr, 0, 0, 0 )
OnExit, HandleExit
Return
HookProc( hWinEventHook, Event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime )
{
if Event ; EVENT_SYSTEM_FOREGROUND = 0x3
{
WinGetTitle, title, ahk_id %hWnd%
If title = The page at http://www.autohotkey.com says: ; code copy popup
WinClose, ahk_id %hWnd%
}
}
SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags)
{
DllCall("CoInitialize", Uint, 0)
return DllCall("SetWinEventHook"
, Uint,eventMin
, Uint,eventMax
, Uint,hmodWinEventProc
, Uint,lpfnWinEventProc
, Uint,idProcess
, Uint,idThread
, Uint,dwFlags)
}
UnhookWinEvent()
{
Global
DllCall( "UnhookWinEvent", Uint,hWinEventHook )
DllCall( "GlobalFree", UInt,&HookProcAdr ) ; free up allocated memory for RegisterCallback
}
HandleExit:
UnhookWinEvent()
ExitApp
Return |
| DeWild1 wrote: | | is there anyway to sense a new process being started? |
Maybe with another type of system hook. I wrote a script a while back to monitor for new processes but it is timer based.
| Anonymous wrote: | | Serenity, this works swell in XP, but can you tell why this may not work in Vista?, what is wrong Smile |
I don't know why it won't work in Vista. Could you try the script in the first post to see if EVENT_SYSTEM_FOREGROUND is being sent? _________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
Guest
|
Posted: Fri Dec 12, 2008 9:34 pm Post subject: |
|
|
| Anonymous wrote: | | Serenity, this works swell in XP, but can you tell why this may not work in Vista?, what is wrong Smile |
| Serenity wrote: | | I don't know why it won't work in Vista. Could you try the script in the first post to see if EVENT_SYSTEM_FOREGROUND is being sent? |
Hello there Serenity. Hope you are going to have a wonderful day!
When I add this line below, I do receive a 0x3 response on Vista
| Code: |
HookProc( hWinEventHook, Event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime )
{
if Event ; EVENT_SYSTEM_FOREGROUND = 0x3
{
tooltip, %event%
WinGetClass, class, ahk_id %hWnd%
If class = Notepad
WinClose, ahk_class Notepad
}
}
|
Basically, just to sum it up..., I was wishing for something here I can turn on and off, that will block any & all new windows,guis,dialougs--all of them--from ever appearing, ... ideally before such Windows are created. Can this be done? Thank you so much.
kindest regards  |
|
| Back to top |
|
 |
DeWild1
Joined: 30 Apr 2006 Posts: 358 Location: Shigle Springs
|
Posted: Tue Dec 16, 2008 10:56 pm Post subject: |
|
|
| Anonymous wrote: | | Anonymous wrote: | | Serenity, this works swell in XP, but can you tell why this may not work in Vista?, what is wrong Smile |
| Serenity wrote: | | I don't know why it won't work in Vista. Could you try the script in the first post to see if EVENT_SYSTEM_FOREGROUND is being sent? |
Hello there Serenity. Hope you are going to have a wonderful day!
When I add this line below, I do receive a 0x3 response on Vista
| Code: |
HookProc( hWinEventHook, Event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime )
{
if Event ; EVENT_SYSTEM_FOREGROUND = 0x3
{
tooltip, %event%
WinGetClass, class, ahk_id %hWnd%
If class = Notepad
WinClose, ahk_class Notepad
}
}
|
Basically, just to sum it up..., I was wishing for something here I can turn on and off, that will block any & all new windows,guis,dialougs--all of them--from ever appearing, ... ideally before such Windows are created. Can this be done? Thank you so much.
kindest regards |
Ya know, Vista sucks.. I thought I had the same problem with another type of hook... http://www.autohotkey.com/forum/viewtopic.php?p=233730#233730
As it turned out, I rebooted and all was well..
I am having trouble right now with AHK - Vista with it even simply activating a window... Something that has always worked and the same code worked fine 3 or 4 days ago... Then I realized - remembered, (after reading your post), that I have not rebooted in about a week... Stupid Vista...
Serenity, I will test now and after a reboot..  _________________ CPULOCK.com
virusSWAT.com
Computer Repair Computer Service.com
911PCFIX.com |
|
| Back to top |
|
 |
DeWild1
Joined: 30 Apr 2006 Posts: 358 Location: Shigle Springs
|
Posted: Tue Dec 16, 2008 11:12 pm Post subject: |
|
|
Swwwweeetness.. Did not have to reboot, and it works.. You are my HERO!!!!!!!!
Thank you!!!!!!!!!!
BTW, I changed it to
| Code: |
If InStr( Title, "some_title_name_with_no_spaces" )
|
and FYI, you have to have it do a msgbox, then winactivate to be 100% dependable.... Otherwise it did not detect it.. (I am sure a reboot would help my stupid Vista though) _________________ CPULOCK.com
virusSWAT.com
Computer Repair Computer Service.com
911PCFIX.com |
|
| Back to top |
|
 |
G40 Guest
|
Posted: Wed Jan 14, 2009 6:49 am Post subject: |
|
|
I am curious about this process below, too, ... Serenity, is it possible to create a function which basically totally eliminates any new popups whilst it is activated?
| Anonymous wrote: | | Anonymous wrote: | | Serenity, this works swell in XP, but can you tell why this may not work in Vista?, what is wrong Smile |
| Serenity wrote: | | I don't know why it won't work in Vista. Could you try the script in the first post to see if EVENT_SYSTEM_FOREGROUND is being sent? |
Hello there Serenity. Hope you are going to have a wonderful day!
When I add this line below, I do receive a 0x3 response on Vista
| Code: |
HookProc( hWinEventHook, Event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime )
{
if Event ; EVENT_SYSTEM_FOREGROUND = 0x3
{
tooltip, %event%
WinGetClass, class, ahk_id %hWnd%
If class = Notepad
WinClose, ahk_class Notepad
}
}
|
Basically, just to sum it up..., I was wishing for something here I can turn on and off, that will block any & all new windows,guis,dialougs--all of them--from ever appearing, ... ideally before such Windows are created. Can this be done? Thank you so much.
kindest regards  |
|
|
| Back to top |
|
 |
Zoplike Guest
|
Posted: Sun Feb 08, 2009 8:45 pm Post subject: |
|
|
[color=green]Just curious, is this even possible ... for some kinda function which can be set on or off (when needed), for the blockage of all desktop dialogs or new GUI instances,... aka. to quiet things down a bit? Like a super-charged Browser pop-up ad blocker, ... but for the entire windows system?  |
|
| Back to top |
|
 |
pantagruel
Joined: 08 Oct 2006 Posts: 96 Location: denmark
|
Posted: Fri Jun 19, 2009 1:41 pm Post subject: Events caught multiple times? |
|
|
Hi,
UPDATED: Never mind, it was embarrassingly obvious once I took a break and then went back and looked at the code.
I want to catch different types of window opening events, for example system alerts, to do this I have the following:
| Code: |
#SingleInstance Force
#Persistent
SetBatchLines,-1
HookProcAdr := RegisterCallback( "HookProc", "F" )
hWinEventHook := SetWinEventHook( 0x3, 0x3, 0, HookProcAdr, 0, 0, 0 )
OnExit, HandleExit
Return
HookProc( hWinEventHook, Event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime )
{
if Event ; EVENT_SYSTEM_ALERT = 0x2
{
WinGetTitle, title, ahk_id %hWnd%
FileAppend,EVENT_SYSTEM_ALERT %A_NOW% %title% %hWnd% `n,c:\temp\autohotkey.log
If InStr( title, "Password" ){
WinClose,ahk_id %hWnd%
}
}
if Event ; EVENT_SYSTEM_DIALOGSTART = 0x10
{
WinGetTitle, title, ahk_id %hWnd%
FileAppend, EVENT_SYSTEM_DIALOGSTART %A_NOW% %title% %hWnd% `n,c:\temp\autohotkey.log
If InStr(title, "Password" ){
WinClose,ahk_id %hWnd%
}}
}
SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags)
{
DllCall("CoInitialize", Uint, 0)
return DllCall("SetWinEventHook"
, Uint,eventMin
, Uint,eventMax
, Uint,hmodWinEventProc
, Uint,lpfnWinEventProc
, Uint,idProcess
, Uint,idThread
, Uint,dwFlags)
}
UnhookWinEvent()
{
Global
DllCall( "UnhookWinEvent", Uint,hWinEventHook )
DllCall( "GlobalFree", UInt,&HookProcAdr ) ; free up allocated memory for RegisterCallback
}
HandleExit:
UnhookWinEvent()
ExitApp
Return
|
now one thing you might notice is that where the event is caught I have a fileappend, I would actually like that in the If block where I find out if it matches the title I am looking for but if I do that the alert which I would like to click on is never clicked on.
In fact without this fileappend or some similar thing I have to basically click on another window and then click back on the window that has popped up the alert.
Now as for the info that get's appended to that file:
| Quote: | EVENT_SYSTEM_ALERT 20090619142657 C:\RenderingService 24248482
EVENT_SYSTEM_DIALOGSTART 20090619142657 C:\RenderingService 24248482
EVENT_SYSTEM_ALERT 20090619142659 \\Siasgb31\test files 21168570
EVENT_SYSTEM_DIALOGSTART 20090619142659 \\Siasgb31\test files 21168570
EVENT_SYSTEM_ALERT 20090619142701 Microsoft Word 36897788
EVENT_SYSTEM_DIALOGSTART 20090619142701 Microsoft Word 36897788
EVENT_SYSTEM_ALERT 20090619142702 9110210
EVENT_SYSTEM_DIALOGSTART 20090619142702 Password 9110210
EVENT_SYSTEM_ALERT 20090619142702 Microsoft Word 36897788
EVENT_SYSTEM_DIALOGSTART 20090619142702 Microsoft Word 36897788
EVENT_SYSTEM_ALERT 20090619142709 autohotkey.log - Notepad 17498464
EVENT_SYSTEM_DIALOGSTART 20090619142709 autohotkey.log - Notepad 17498464
EVENT_SYSTEM_ALERT 20090619142709 autohotkey.log - Notepad 17498464
EVENT_SYSTEM_DIALOGSTART 20090619142709 autohotkey.log - Notepad 17498464
EVENT_SYSTEM_ALERT 20090619142711 196702
EVENT_SYSTEM_DIALOGSTART 20090619142711 196702
EVENT_SYSTEM_ALERT 20090619142712 C:\RenderingService 24248482
EVENT_SYSTEM_DIALOGSTART 20090619142712 C:\RenderingService 24248482
EVENT_SYSTEM_ALERT 20090619142714 C:\Temp 4457096
EVENT_SYSTEM_DIALOGSTART 20090619142714 C:\Temp 4457096
EVENT_SYSTEM_ALERT 20090619142716 Untitled - Notepad 7995806
EVENT_SYSTEM_DIALOGSTART 20090619142716 Untitled - Notepad 7995806
EVENT_SYSTEM_ALERT 20090619142812 C:\Temp 4457096
EVENT_SYSTEM_DIALOGSTART 20090619142812 C:\Temp 4457096
EVENT_SYSTEM_ALERT 20090619142814 Microsoft Word 36897788
EVENT_SYSTEM_DIALOGSTART 20090619142814 Microsoft Word 36897788
EVENT_SYSTEM_ALERT 20090619142814 Microsoft Word 36897788
EVENT_SYSTEM_DIALOGSTART 20090619142814 Microsoft Word 36897788
EVENT_SYSTEM_ALERT 20090619142817 196702
EVENT_SYSTEM_DIALOGSTART 20090619142817 196702
EVENT_SYSTEM_ALERT 20090619142818 C:\Temp 4457096
EVENT_SYSTEM_DIALOGSTART 20090619142818 C:\Temp 4457096
EVENT_SYSTEM_ALERT 20090619142819 Untitled - Notepad 19071492
EVENT_SYSTEM_DIALOGSTART 20090619142819 Untitled - Notepad 19071492
EVENT_SYSTEM_ALERT 20090619142828 C:\Temp 4457096
EVENT_SYSTEM_DIALOGSTART 20090619142828 C:\Temp 4457096
EVENT_SYSTEM_ALERT 20090619142829 Untitled - Notepad 19137102
EVENT_SYSTEM_DIALOGSTART 20090619142829 Untitled - Notepad 19137102
EVENT_SYSTEM_ALERT 20090619142835 C:\Temp 4457096
EVENT_SYSTEM_DIALOGSTART 20090619142835 C:\Temp 4457096
EVENT_SYSTEM_ALERT 20090619142837 WinEventHandler.ahk - Notepad 7275152
EVENT_SYSTEM_DIALOGSTART 20090619142837 WinEventHandler.ahk - Notepad 7275152
EVENT_SYSTEM_ALERT 20090619142901 196702
EVENT_SYSTEM_DIALOGSTART 20090619142901 196702
EVENT_SYSTEM_ALERT 20090619142901 18874774
EVENT_SYSTEM_DIALOGSTART 20090619142902 18874774
EVENT_SYSTEM_ALERT 20090619151752 \\Siasgb31\test files 21168570
EVENT_SYSTEM_DIALOGSTART 20090619151752 \\Siasgb31\test files 21168570
EVENT_SYSTEM_ALERT 20090619151754 Microsoft Word 9765434
EVENT_SYSTEM_DIALOGSTART 20090619151754 Microsoft Word 9765434
EVENT_SYSTEM_ALERT 20090619151755 25428762
EVENT_SYSTEM_DIALOGSTART 20090619151755 Password 25428762
EVENT_SYSTEM_ALERT 20090619151755 Microsoft Word 9765434
EVENT_SYSTEM_DIALOGSTART 20090619151755 Microsoft Word 9765434
EVENT_SYSTEM_ALERT 20090619151759 \\Siasgb31\test files 21168570
EVENT_SYSTEM_DIALOGSTART 20090619151759 \\Siasgb31\test files 21168570
EVENT_SYSTEM_ALERT 20090619151801 C:\Temp 4457096
EVENT_SYSTEM_DIALOGSTART 20090619151801 C:\Temp 4457096
EVENT_SYSTEM_ALERT 20090619151802 Untitled - Notepad 8126598
EVENT_SYSTEM_DIALOGSTART 20090619151802 Untitled - Notepad 8126598
|
Which seems wrong to me, most of these windows are not alerts or dialogs of any sort. Basically what it seems to be doing is the same thing as looping through Windows, which I don't want.
I know this currently would be doable by looping through the windows etc. but the reason I am using this is I would like to achieve a greater deal of control.
So anyway, my questions are:
1. How can I make it so it just catches the event of an alert box?
2. How can I make it so that I don't have to do something like the fileappend to catch the alert and close it?
3. Can anyone explain why that happens - that if the fileappend is there I close the alert, and if it isn't there it just hangs around forever?
If it affects anything this is an alert raised from Word, but I am going to want to be able to catch alerts from all sorts of different applications.
As an easier way to test this, if I have the code:
| Code: | if Event ; EVENT_SYSTEM_ALERT = 0x2
{
If InStr( title, "test.ahk" ){
WinActivate
Send,{Escape}
}
}
|
and a file named test.ahk with the following:
If I start test.ahk my alert ("hi") hangs around forever, but it will be closed if I move the focus to another window, and then back to the alert
But if the code in my event catching autohotkey script is the following:
| Code: | if Event ; EVENT_SYSTEM_ALERT = 0x2
{
FileAppend,EVENT_SYSTEM_ALERT %A_NOW% %hWnd% `n,c:\temp\autohotkey.log
WinGetTitle, title, ahk_id %hWnd%
If InStr( title, "test.ahk" ){
WinActivate
Send,{Escape}
}
} |
then nearly instantaneously with the alert popping up it is killed. However when I look in the log there is not just one message about that particular window that I just killed but every other window on the system, despite them not being alerts (as per the earlier quoted example)
WHY???!??
(damn, I hope this was reasonably clear) |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|