-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathclass_ShellHook.ahk
86 lines (66 loc) · 3.41 KB
/
class_ShellHook.ahk
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
;==================================================================
; SHELL HOOK v1.0.1
; Author: Daniel Shuy
;
; Attaches a Shell Hook to the Windows API to listen for Shell events
;==================================================================
#Include %A_ScriptDir%\OnExitConst.ahk
class ShellHook {
;==================================================================
; hookCode Constants (refer to WinUser.h)
; see https://msdn.microsoft.com/en-us/library/windows/desktop/ms644989(v=vs.85).aspx
;==================================================================
; A top-level, unowned window has been created. The window exists when the system calls this hook.
static HSHELL_WINDOWCREATED := 1
; A top-level, unowned window is about to be destroyed. The window still exists when the system calls this hook.
static HSHELL_WINDOWDESTROYED := 2
; The shell should activate its main window.
static HSHELL_ACTIVATESHELLWINDOW := 3
; The activation has changed to a different top-level, unowned window.
static HSHELL_WINDOWACTIVATED := 4
; A window is being minimized or maximized. The system needs the coordinates of the minimized rectangle for the window. If the Shell procedure handles the WM_COMMAND message, it should not call CallNextHookEx.
static HSHELL_GETMINRECT := 5
; The title of a window in the task bar has been redrawn.
static HSHELL_REDRAW := 6
; The user has selected the task list. A shell application that provides a task list should return TRUE to prevent Windows from starting its task list.
static HSHELL_TASKMAN := 7
; Keyboard language was changed or a new keyboard layout was loaded.
static HSHELL_LANGUAGE := 8
; A window's system menu is brought up by right clicking its taskbar button
static HSHELL_SYSMENU := 9
; A window is forced to exit
static HSHELL_ENDTASK := 10
; The accessibility state has changed.
static HSHELL_ACCESSIBILITYSTATE := 11
; The user completed an input event (for example, pressed an application command button on the mouse or an application command key on the keyboard), and the application did not handle the WM_APPCOMMAND message generated by that input.
static HSHELL_APPCOMMAND := 12
; A top-level window is being replaced. The window exists when the system calls this hook.
static HSHELL_WINDOWREPLACED := 13
; A window is replacing the top-level window.
static HSHELL_WINDOWREPLACING := 14
; A window is moved to a different monitor.
static HSHELL_MONITORCHANGED := 16
static HSHELL_HIGHBIT = 0x8000
static HSHELL_FLASH := HSHELL_REDRAW|HSHELL_HIGHBIT ; A window is flashed.
static HSHELL_RUDEAPPACTIVATED := HSHELL_WINDOWACTIVATED|HSHELL_HIGHBIT ; Not sure what is the difference from HSHELL_WINDOWACTIVATED.
;==================================================================
__New(hWnd) {
this.hWnd := hWnd
this.Register()
}
Register() {
DllCall("RegisterShellHookWindow", UInt, this.hWnd)
hook := DllCall("RegisterWindowMessage", Str, "SHELLHOOK")
OnMessage(hook, ObjBindMethod(this, "ShellProc"))
OnExit(ObjBindMethod(this, "Deregister"), OnExitConst.ON_EXIT_ADD_AFTER)
}
Deregister() {
; Deregister Shell Hook
DllCall("DeregisterShellHookWindow", UInt, this.hWnd)
}
; Override to implement actions to perform when a Shell event occurs
; Should we perform hookCode comparison here and provide an abstract event-handling method for each hook instead?
ShellProc(hookCode, id) {
return
}
}