 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
majkinetor
Joined: 24 May 2006 Posts: 3714 Location: Belgrade
|
Posted: Mon Aug 27, 2007 9:48 am Post subject: [tutorial] WinEvent Hook |
|
|
Recent callback addition to AHK language makes us able to create so called "out of context" hooks. This eliminites need for separate hook dll that is for instance used in Dock module.
This is the sample how to monitor when system menu is open/closed.
| Code: | CoordMode, tooltip, screen
#SingleInstance, force
#Persistent
HookProcAdr := RegisterCallback("HookProc", "F" )
API_SetWinEventHook(4,5,0,HookProcAdr,0,0,0)
API_SetWinEventHook(0xA,0xB,0,HookProcAdr,0,0,0)
return
HookProc(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime ){
if event = 4
s := "Menu start"
else if event = 5
s := "Menu close"
else if event = 10
s := "Moving started"
else s := "Moving stoped"
ToolTip, %s%, 0, 0
}
API_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)
} |
_________________
 |
|
| Back to top |
|
 |
nonov Guest
|
Posted: Sat May 31, 2008 10:14 am Post subject: |
|
|
hi majkinetor
thanks for kindly tutorial (i just wonder that why no replies here?)
i've tried to make a replacement of sysmenu. but there were few problems
1) can i hook sysmenu only? rather than all popup menus by right mouse click
2) is there more elegant way rather than closing sysmenu by sending {ALT} key?
Thanks !!!
| Code: | #SingleInstance, force
#Persistent
SetKeyDelay, -1 ;close sysmenu real fast!!!
SetBatchLines, -1
HookProcAdr := RegisterCallback("HookProc", "F" )
API_SetWinEventHook(4,5,0,HookProcAdr,0,0,0)
API_SetWinEventHook(0xA,0xB,0,HookProcAdr,0,0,0)
Menu, Replacement, Add, SysMenu Hook Testing!!!, Test
Test:
return
HookProc(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime ) {
if event = 4
{
Send, {Alt} ;close sysmenu!!!
Menu, Replacement, Show
}
}
API_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)
} |
|
|
| Back to top |
|
 |
nonov Guest
|
Posted: Sat May 31, 2008 10:19 am Post subject: |
|
|
the "Sysmenu" i mentioned was meant for System Menu that pops up from caption bar or when pressing Alt+Space
Thanks!!! |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3714 Location: Belgrade
|
Posted: Sat May 31, 2008 2:07 pm Post subject: |
|
|
I don't know at the moment but I also had need for that so I will check out. If I find out anything useful, I will let you know. _________________
 |
|
| 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
|