这是一个挺老的示例,可能使用有问题。仅供参考

#NoEnv
#SingleInstance Force
SetBatchLines, -1
SendMode Input

; 窗口切换钩子调用
DllCall("RegisterShellHookWindow", "Ptr", A_ScriptHwnd)
OnMessage(DllCall("RegisterWindowMessage", "Str", "ShellHook"), "ShellEvent")

#ifWinActive ahk_class TXGuiFoundation
~1::
~2::
~3::
~4::
~5::
~6::
~7::
~8::
~9::
~Space::
~Enter::
~Backspace::
~LButton::
GetCaret(x, y)
if (x!=0) && (y!=0) {
  acc获取缓存历史内容:=acc获取.Value
  acc获取:=ACC获取文本(x,y)
  中文热字串:=StrReplace(acc获取.Value,acc获取缓存历史内容,"")
  if (中文热字串="中文帮助") {
    SendInput {Backspace 4}
    SendInput {text}可以在群文件里,搜中文帮助文档
  }
}
return
#ifWinActive

;活动窗口切换监控【异步触发】
ShellEvent(wParam, lParam) {
  if WinActive("ahk_class TXGuiFoundation")
    Gosub ~Enter
 }

; 获取光标位置(坐标相对于屏幕)
; From Acc.ahk by Sean, jethrow, malcev, FeiYue
GetCaret(Byref CaretX="", Byref CaretY="")
{
  static init
  CoordMode, Caret, Screen
  CaretX:=A_CaretX, CaretY:=A_CaretY
  if (!CaretX or !CaretY)
    Try {
      if (!init)
        init:=DllCall("LoadLibrary","Str","oleacc","Ptr")
  VarSetCapacity(IID,16), idObject:=OBJID_CARET:=0xFFFFFFF8
    , NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0, IID, "Int64")
    , NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81, IID, 8, "Int64")
  if DllCall("oleacc\AccessibleObjectFromWindow"
    , "Ptr",WinExist("A"), "UInt",idObject, "Ptr",&IID, "Ptr*",pacc)=0
  {
    Acc:=ComObject(9,pacc,1), ObjAddRef(pacc)
      , Acc.accLocation(ComObj(0x4003,&x:=0), ComObj(0x4003,&y:=0)
      , ComObj(0x4003,&w:=0), ComObj(0x4003,&h:=0), ChildId:=0)
      , CaretX:=NumGet(x,0,"int"), CaretY:=NumGet(y,0,"int")
  }
}
return {x:CaretX, y:CaretY}
}

ACC获取文本(x="", y="", ByRef Acc="", ByRef child="")
{
  static h:=DllCall("LoadLibrary", "Str","oleacc.dll")
  pos:=(x=""||y="" ? 0*DllCall("GetCursorPos","Int64*",pt)+pt : x&0xFFFFFFFF|y<<32)
  id:=DllCall("WindowFromPoint", "Int64",pos)
  SendMessage, WM_GETOBJECT:=0x3D, 0, 1,, ahk_id %id%
  arr:=[], Acc:=child:="", VarSetCapacity(var,8+2*A_PtrSize,0)
  if DllCall("oleacc\AccessibleObjectFromPoint","Int64",pos,"Ptr*",pacc,"Ptr",&var)=0
  {
    Acc:=ComObjEnwrap(9,pacc,1), child:=NumGet(var,8,"UInt")
    Try arr["Name"]:=Acc.accName(child)
    Try arr["Value"]:=Acc.accValue(child)
    return arr
  }
}

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。