- 这个 AutoHotkey 脚本应该可以满足您的要求。
- 它已经在记事本 (Windows 7) 上进行了测试,应该可以很容易地适应其他使用标准上下文菜单的程序,这些程序仍然在绝大多数软件中使用。尽管许多程序使用自定义菜单栏,但上下文菜单通常仍然是标准上下文菜单。
- 我提供了两个脚本,一个将显示工具提示并阻止在按下 任何 菜单项时触发菜单项,这有助于理解和诊断目的。
如果其文本字符串以“打开”开头,第二个脚本将显示工具提示并阻止触发任何菜单项。
- 注意:记事本菜单项的文本是
Open... Ctrl+O (Open...[tab]Ctrl+O) 而不仅仅是“打开”。
-
;==================================================
;tested on Notepad (Windows 7)
;block any clicks on any menu items when notepad is the active window
;note: to bypass this and click an item anyway, use ctrl+click
;note: requires Acc.ahk library in AutoHotkey\Lib folder
;https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/Acc.ahk
;on right of screen right-click Raw, Save target as...
#IfWinActive, ahk_class Notepad
;LButton::
CoordMode, Mouse, Screen
MouseGetPos, , , hWnd
WinGetClass, vWinClass, ahk_id %hWnd%
if vWinClass in #32768
{
vCount++ ;your code here
ToolTip blocked %vCount%, 500, 200 ;your code here
Return
}
SendInput {LButton Down}
KeyWait, LButton
MouseGetPos, vPosX, vPosY, hWnd
WinGetClass, vWinClass, ahk_id %hWnd%
if vWinClass in #32768
{
ControlSend, Dummy, {Click, 0, 0}, ahk_class Notepad
vCount++ ;your code here
ToolTip blocked %vCount%, 500, 200 ;your code here
Return
}
SendInput {LButton Up}
Return
#IfWinActive
;==================================================
;tested on Notepad (Windows 7)
;block any clicks on the 'open' menu item when notepad is the active window
;note: to bypass this and click an item anyway, use ctrl+click
;note: requires Acc.ahk library in AutoHotkey\Lib folder
;https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/Acc.ahk
;on right of screen right-click Raw, Save target as...
#IfWinActive, ahk_class Notepad
LButton::
CoordMode, Mouse, Screen
MouseGetPos, , , hWnd
WinGetClass, vWinClass, ahk_id %hWnd%
if vWinClass in #32768
{
vItemText := ""
oAcc := Acc_Get("Object", "1", 0, "ahk_id " hWnd)
Loop, % oAcc.accChildCount
if (oAcc.accState(A_Index) & 0x80) ;MF_HILITE := 0x80
if (1, vItemText := oAcc.accName(A_Index))
break
if (SubStr(vItemText, 1, 4) = "Open")
{
vCount++ ;your code here
ToolTip blocked %vCount%, 500, 200 ;your code here
Return
}
}
SendInput {LButton Down}
KeyWait, LButton
MouseGetPos, vPosX, vPosY, hWnd
WinGetClass, vWinClass, ahk_id %hWnd%
if vWinClass in #32768
{
ControlSend, Dummy, {Click, 0, 0}, ahk_class Notepad
vItemText := ""
oAcc := Acc_Get("Object", "1", 0, "ahk_id " hWnd)
Loop, % oAcc.accChildCount
if (oAcc.accState(A_Index) & 0x80) ;MF_HILITE := 0x80
if (1, vItemText := oAcc.accName(A_Index))
break
if (SubStr(vItemText, 1, 4) = "Open")
{
vCount++ ;your code here
ToolTip blocked %vCount%, 500, 200 ;your code here
Return
}
}
SendInput {LButton Up}
Return
#IfWinActive
;==================================================
注意:
下面两个链接中贴出的代码示例,实现了相关目标。
Is it possible to catch the close button and minimize the window instead? AutoHotKey
AutoHotKey: Run code on Window Event (Close)
注意:
函数JEE_MenuIsActive,如下链接,可用于检查是否
菜单栏/系统菜单栏处于活动状态
为了区分标题栏菜单和右键单击上下文菜单。
GUI 命令:完成重新思考 - AutoHotkey 社区
https://autohotkey.com/boards/viewtopic.php?f=5&t=25893