-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathclass_MenuInterceptor.AHK
79 lines (62 loc) · 2.5 KB
/
class_MenuInterceptor.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
#Persistent
; 2022-07-23 (Ixiko): modified to work with different system languages. Complete the respective menu items in your language.
; The original author: casperharkin
; link: https://github.com/casperharkin/Menu-Interceptor
; ################################################################################################
; ############# Notepad Example - Watch for Clicks on Menu Items Undo, Delete, Cut #############
; ################################################################################################
Global MI_Data
MI := New MenuInterceptor("ahk_class Notepad", "Undo,Delete,Cut,Help", "0x0004", "0x0005")
return
Cut(MenuName){
ToolTip % "You Clicked " MenuName "!"
}
Undo(MenuName) {
ToolTip % "You Clicked " MenuName "!"
}
Delete(MenuName) {
ToolTip % "You Clicked " MenuName "!"
}
Help(MenuName) {
ToolTip % "You Clicked " MenuName "!"
}
; ################################################################################################
Class MenuInterceptor {
__New(WindowClass, MenusToIntercept, Event_Menu_Start, Event_Menu_End) {
Static
lang := GetSystemLanguage()
MenusToIntercept := lang ~= "i)German" ? "Rückgängig,Löschen,Ausschneiden,Hilfe anzeigen" : MenusToIntercept
MI_Data := {}
MI_Data.WindowClass := WindowClass
MI_Data.MenusToIntercept := StrSplit(MenusToIntercept ,",")
MI_Data.FuncToCall := StrSplit("Undo,Delete,Cut,Help" ,",")
MI_Data.Event_Menu_Start := Event_Menu_Start
MI_Data.Event_Menu_End := Event_Menu_End
Acc_SetWinEventHook( Event_Menu_Start ? Event_Menu_Start : 0x0004
, Event_Menu_End ? Event_Menu_End : 0x0005
, pCallback := RegisterCallback("MenuInterceptor.WinEvent"))
}
WinEvent(hHook, event, hWnd, idObject, idChild, eventThread, eventTime) {
Critical
Sleep 200 ; This is needed to Drop the click between firing the event and checking text
if WinActive(MI_Data.WindowClass) {
If (hHook = 4) {
KeyWait, LButton, D
MI_Data.Text := MenuInterceptor.GetInfoUnderCursor()
For mNr, Value in MI_Data.MenusToIntercept
If InStr(MI_Data.Text, Value) {
cFunc := MI_Data.FuncToCall[mNr]
%cFunc%(MI_Data.Text)
}
}
}
}
GetInfoUnderCursor() {
Acc := Acc_ObjectFromPoint(child)
if !(value := Acc.accValue(child))
value := Acc.accName(child)
Return value
}
}
#include ..\libs\a-f\ACC_more.ahk
#include ..\libs\g-n\GetSystemLanguage.ahk