先将Everything最小化,脚本从最小化隐藏界面无感切换到搜索框后,再还原最小化
Everything无感后台切换演示.ahk 【老脚本,仅供参考】
#NoTrayIcon
SetTitleMatchMode, 2
; 先将Everything最小化,脚本从最小化隐藏界面无感切换到搜索框后,再还原最小化
WinSet, Transparent, 0, ahk_class EVERYTHING
WinActivate, ahk_class EVERYTHING
WinGet, id, ID, ahk_class EVERYTHING
ControlSetText, Edit1, 修改内容, ahk_class EVERYTHING
clipboard := Acc_GetTextFromPath(id, "4.1.4.1.4")
WinMinimize, ahk_class EVERYTHING
WinSet, Transparent, 255, ahk_class EVERYTHING
Return
F1::Everything变量名("搜索(S)")
F2::Everything变量名("音频")
F3::Everything变量名("帮助")
; MsgBox,% Acc_GetAllText(0x1194A) ;成功,但速度比较慢
Acc_GetTextFromPath(id,str)
{
SetBatchLines, -1
SetTitleMatchMode, 2
DetectHiddenWindows, On
if (arr:=Acc_GetObjectFromPath(id, str))
{
; Try arr[1].accDoDefaultAction()
Try value := Arr[1].accValue()
If (!value)
Try value := Arr[1].accName()
; MsgBox,% Acc_Children(arr[2])
}
; MsgBox,% value
return,value
}
Acc_GetTextFromHwnd(hWnd)
{
static arr, text
arr:=[], text:="", hwnd:=Acc_ObjectFromWindow(hwnd, 0)
arr.Push(0)
For i,v in Acc_Children(Acc:=hwnd)
{
Role:=Name:=Value:="", j:=IsObject(v)
Try Name:=j ? v.accName(0) : Acc.accName(v)
text:=Name
}
arr.Pop()
return (s:=text, text:="") ? s:s
}
Everything变量名(命令)
{
SetBatchLines, -1
SetTitleMatchMode, 2
DetectHiddenWindows, On
WinGet, id, ID, Everything ahk_class EVERYTHING
Everything变量名:={"":""
, "搜索(S)" : "3.4"
, "音频" : "3.4.1.1.c13"
, "帮助" : "3.7" }
if (arr:=Acc_GetObjectFromPath(id, Everything变量名[命令]))
{
; Try arr[1].accDoDefaultAction(arr[2])
; Try arr[1].accDoDefaultAction()
Try value := Arr[1].accValue()
If (!value)
Try value := Arr[1].accName()
MsgBox,% value
return
}
}
Acc_GetAllText(hwnd, info="", first=1)
{
static arr, text
if (first)
arr:=[], text:="", hwnd:=Acc_ObjectFromWindow(hwnd, 0)
arr.Push(0)
For i,v in Acc_Children(Acc:=hwnd)
{
arr[arr.length()]++, path:=""
Loop, % arr.length()
path.=(A_Index=1 ? "" : ".") . arr[A_Index]
Role:=Name:=Value:="", j:=IsObject(v)
Try Role:=j ? v.accRole(0) : Acc.accRole(v)
Try Name:=j ? v.accName(0) : Acc.accName(v)
Try Value:=j ? v.accValue(0) : Acc.accValue(v)
; MsgBox,% Name
path:=j ? path : RegExReplace(path, "(\w+)$", "c$1")
; MsgBox,% path
if (!info.role||Role=info.role)
and (!info.name||Name~=info.name)
and (!info.value||Value~=info.value)
text.=path " ---- " Acc_GetRoleText(Role) " "
. Format("0x{:X}",Role) " [" SubStr(Name,1,60)
. "][" SubStr(Value,1,60) "]`r`n"
if (j)
Acc_GetAllText(v, info, 0)
}
arr.Pop()
if (first)
return (s:=text, text:="") ? s:s
}
Acc_GetObjectFromPath(hwnd, path, info="", Acc=0, first=1)
{
if (first)
hwnd:=Acc_ObjectFromWindow(hwnd, 0)
if !IsObject(v:=hwnd) and !IsObject(Acc)
return
Loop, Parse, path, ., c C
{
if !IsObject(Acc:=v)
return
if (i:=A_LoopField)="X"
{
path:=Trim(SubStr(path, InStr(path,"X")+1), ".")
For k,v in Acc_Children(Acc)
if (arr:=Acc_GetObjectFromPath(v,path,info,Acc,0))
return arr
return
}
if (j:=Acc.accChildCount)<i or (j<1)
return
v:=Acc_Children(Acc,i)
}
Role:=Name:=Value:="", j:=IsObject(v)
Try Role:=j ? v.accRole(0) : Acc.accRole(v)
Try Name:=j ? v.accName(0) : Acc.accName(v)
Try Value:=j ? v.accValue(0) : Acc.accValue(v)
if (!info.role||Role=info.role)
and (!info.name||Name~=info.name)
and (!info.value||Value~=info.value)
return (j ? [v,0] : [Acc,v])
}
Acc_GetInfoUnderCursor()
{
; MouseGetPos,,,, cid, 2
; SendMessage, WM_GETOBJECT:=0x3D, 0, 1,, ahk_id %cid%
Acc:=Acc_ObjectFromPoint(child)
Try Name:=Acc.accName(child)
Try Value:=Acc.accValue(child)
Try Role:=Format("0x{:X}", Acc.accRole(child))
Try State:=Format("0x{:X}", Acc.accState(child))
path:=Acc_GetAccPath(Acc, child, hwnd)
WinGetTitle, title, ahk_id %hwnd%
WinGetClass, class, ahk_id %hwnd%
return { Path:path, Hwnd:hwnd, Title:title, Class:class
, Name:Name, Value:Value, Role:Role, State:State }
}
Acc_GetAccPath(Acc, ChildID, ByRef hwnd)
{
static DesktopHwnd:=DllCall("GetDesktopWindow", "ptr")
hwnd:=PreHwnd:=t2:=""
While AccHwnd:=Acc_WindowFromObject(Parent:=Acc_Parent(Acc))
{
t1:=(ChildID=0?"":"c") . Acc_GetEnumIndex(Acc, ChildID)
if (PreHwnd!="" && AccHwnd!=PreHwnd)
hwnd:=PreHwnd
if (t1="" || AccHwnd=DesktopHwnd)
Break
t2:=t1 "." t2, PreHwnd:=AccHwnd
, (ChildID=0 ? Acc:=Parent:""), ChildID:=0
}
return SubStr(t2,1,-1)
}
Acc_GetEnumIndex(Acc, ChildID=0)
{
Role:=State:=Name:=""
Try Role :=Acc.accRole(ChildID)
Try State:=Acc.accState(ChildID)
Try Name :=Acc.accName(ChildID)
Pos:=Acc_Location(Acc,ChildID).pos
Count:=Acc.accChildCount
if (ChildID!=0)
{
For Each, child in Acc_Children(Acc)
if !IsObject(child)
{
vRole:=vState:=vName:=""
Try vRole :=Acc.accRole(child)
Try vState:=Acc.accState(child)
Try vName :=Acc.accName(child)
if (vRole=Role) and (vState=State) and (vName=Name)
and (Acc_Location(Acc,child).pos=Pos)
return A_Index
}
return
}
For Each, child in Acc_Children(Acc_Parent(Acc))
if IsObject(child)
{
vRole:=vState:=vName:=""
Try vRole :=child.accRole(0)
Try vState:=child.accState(0)
Try vName :=child.accName(0)
if (vRole=Role) and (vState=State) and (vName=Name)
and (child.accChildCount=Count)
and (Acc_Location(child).pos=Pos)
return A_Index
}
}
; Acc.ahk - thanks Sean, jethrow, jeeswg, teadrinker
Acc_Get(Cmd, ChildPath="", ChildID=0, WinTitle="", WinText="", ExcludeTitle="", ExcludeText="")
{
static properties := {Action:"DefaultAction", DoAction:"DoDefaultAction", Keyboard:"KeyboardShortcut"}
AccObj := IsObject(WinTitle) ? WinTitle
: Acc_ObjectFromWindow( WinExist(WinTitle, WinText, ExcludeTitle, ExcludeText), 0 )
if ComObjType(AccObj, "Name") != "IAccessible"
ErrorLevel := "Could not access an IAccessible Object"
else
{
if RegExMatch(ChildPath,"\.[cC](\w+)$",r)
ChildPath:=SubStr(ChildPath,1,-StrLen(r)), ChildID:=r1
StringReplace, ChildPath, ChildPath, _, %A_Space%, All
AccError:=Acc_Error(), Acc_Error(true)
Loop, Parse, ChildPath, ., %A_Space%
try
{
if A_LoopField is digit
Children:=Acc_Children(AccObj), m2:=A_LoopField ; mimic "m2" output in else-statement
else
RegExMatch(A_LoopField, "(\D*)(\d*)", m)
, Children:=Acc_ChildrenByRole(AccObj, m1), m2:=(m2?m2:1)
if Not Children.HasKey(m2)
throw
AccObj := Children[m2]
}
catch
{
ErrorLevel:="Cannot access ChildPath Item #" A_Index " -> " A_LoopField, Acc_Error(AccError)
if Acc_Error()
throw Exception("Cannot access ChildPath Item", -1, "Item #" A_Index " -> " A_LoopField)
return
}
Acc_Error(AccError)
StringReplace, Cmd, Cmd, %A_Space%, , All
properties.HasKey(Cmd)? Cmd:=properties[Cmd]:""
try
{
if (Cmd = "Location")
ret_val := Acc_Location(AccObj,ChildId+0).pos
else if (Cmd = "Object")
ret_val := AccObj
else if Cmd in Role,State
ret_val := Acc_%Cmd%(AccObj, ChildID+0)
else if Cmd in ChildCount,Selection,Focus
ret_val := AccObj["acc" Cmd]
else
ret_val := AccObj["acc" Cmd](ChildID+0)
}
catch
{
ErrorLevel := """" Cmd """ Cmd Not Implemented"
if Acc_Error()
throw Exception("Cmd Not Implemented", -1, Cmd)
return
}
return ret_val, ErrorLevel:=0
}
if Acc_Error()
throw Exception(ErrorLevel,-1)
}
Acc_Location(Acc, ChildId=0) ; adapted from Sean's code
{
try Acc.accLocation(ComObj(0x4003,&x:=0), ComObj(0x4003,&y:=0)
, ComObj(0x4003,&w:=0), ComObj(0x4003,&h:=0), ChildId)
catch
return
return { x:NumGet(x,0,"int"), y:NumGet(y,0,"int")
, w:NumGet(w,0,"int"), h:NumGet(h,0,"int")
, pos:"x" NumGet(x,0,"int")" y" NumGet(y,0,"int")
. " w" NumGet(w,0,"int") " h" NumGet(h,0,"int") }
}
Acc_Parent(Acc)
{
try parent:=Acc.accParent
return parent?Acc_Query(parent):""
}
Acc_Child(Acc, ChildId=0)
{
try child:=Acc.accChild(ChildId)
return child?Acc_Query(child):""
}
Acc_Init()
{
Static h
If (!h)
h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
}
Acc_WindowFromObject(pacc)
{
Acc_Init()
If DllCall("oleacc\WindowFromAccessibleObject", "Ptr"
, IsObject(pacc)?ComObjValue(pacc):pacc, "Ptr*", hWnd)=0
return hWnd
}
Acc_ObjectFromEvent(ByRef _idChild_, hWnd, idObject, idChild)
{
Acc_Init()
If DllCall("oleacc\AccessibleObjectFromEvent", "Ptr", hWnd
, "UInt", idObject, "UInt", idChild, "Ptr*", pacc, "Ptr"
, VarSetCapacity(varChild,8+2*A_PtrSize,0)*0+&varChild)=0
return ComObjEnwrap(9,pacc,1), _idChild_:=NumGet(varChild,8,"UInt")
}
Acc_ObjectFromPoint(ByRef _idChild_ = "", x = "", y = "")
{
Acc_Init()
If DllCall("oleacc\AccessibleObjectFromPoint", "Int64", x==""||y==""
? 0*DllCall("GetCursorPos","Int64*",pt)+pt:x&0xFFFFFFFF|y<<32, "Ptr*", pacc
, "Ptr", VarSetCapacity(varChild,8+2*A_PtrSize,0)*0+&varChild)=0
return ComObjEnwrap(9,pacc,1), _idChild_:=NumGet(varChild,8,"UInt")
}
Acc_ObjectFromWindow(hWnd, idObject = -4)
{
Acc_Init()
If DllCall("oleacc\AccessibleObjectFromWindow"
, "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr", (VarSetCapacity(IID,16)
+NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64")
+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,IID,8,"Int64"))*0
+&IID, "Ptr*", pacc)=0
return ComObjEnwrap(9,pacc,1)
}
Acc_Children(Acc, N="")
{
if ComObjType(Acc,"Name") != "IAccessible"
ErrorLevel := "Invalid IAccessible Object"
else
{
Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]
if DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc)
, "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren
, cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0
{
ListLines, % (lls:=A_ListLines=0?"Off":"On")?"Off":"Off"
SetBatchLines, % (bch:=A_BatchLines)?"-1":"-1"
Loop, %cChildren%
i:=(A_Index-1)*(A_PtrSize*2+8), child:=NumGet(varChildren,i+8)
, Children[A_Index]:=( (j:=NumGet(varChildren,i)=9)
&& (N=""||N=A_Index) ? Acc_Query(child):child )
, (j ? ObjRelease(child):"")
SetBatchLines, %bch%
ListLines, %lls%
return Children.MaxIndex()?(N=""?Children:Children[N]):""
} else
ErrorLevel := "AccessibleChildren DllCall Failed"
}
if Acc_Error()
throw Exception(ErrorLevel,-1)
}
Acc_ChildrenByRole(Acc, Role)
{
if ComObjType(Acc,"Name")!="IAccessible"
ErrorLevel := "Invalid IAccessible Object"
else
{
Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]
if DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc)
, "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren
, cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0
{
Loop, %cChildren%
{
i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i)
if NumGet(varChildren,i-8)=9
AccChild:=Acc_Query(child), ObjRelease(child)
, Acc_Role(AccChild)=Role?Children.Push(AccChild):""
else
Acc_Role(Acc, child)=Role?Children.Push(child):""
}
return Children.MaxIndex()?Children:"", ErrorLevel:=0
} else
ErrorLevel := "AccessibleChildren DllCall Failed"
}
if Acc_Error()
throw Exception(ErrorLevel,-1)
}
Acc_Query(Acc) ; thanks Lexikos - www.autohotkey.com/forum/viewtopic.php?t=81731&p=509530#509530
{
static IAccessible:="{618736e0-3c3d-11cf-810c-00aa00389b71}"
try return ComObj(9, ComObjQuery(Acc,IAccessible), 1)
}
Acc_Role(Acc, ChildId=0)
{
try return ComObjType(Acc,"Name")="IAccessible"
? Acc_GetRoleText(Acc.accRole(ChildId)):"invalid object"
}
Acc_State(Acc, ChildId=0)
{
try return ComObjType(Acc,"Name")="IAccessible"
? Acc_GetStateText(Acc.accState(ChildId)):"invalid object"
}
Acc_GetRoleText(nRole)
{
Acc_Init()
nSize := DllCall("oleacc\GetRoleText", "Uint", nRole, "Ptr", 0, "Uint", 0)
VarSetCapacity(sRole, (A_IsUnicode?2:1)*nSize)
DllCall("oleacc\GetRoleText", "Uint", nRole, "str", sRole, "Uint", nSize+1)
return sRole
}
Acc_GetStateText(nState)
{
Acc_Init()
nSize := DllCall("oleacc\GetStateText", "Uint", nState, "Ptr", 0, "Uint", 0)
VarSetCapacity(sState, (A_IsUnicode?2:1)*nSize)
DllCall("oleacc\GetStateText", "Uint", nState, "str", sState, "Uint", nSize+1)
return sState
}
Acc_Error(p="")
{
static setting:=0
return p=""?setting:setting:=p
}
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。

评论(0)