因为开机脚本中需要使用热键控制酷狗音乐,所以研究了一下ACC,可以简单实现控制各种不规则的程序界面功能,当然也包括酷狗音乐。
/*
;-----------------------------------
; ACC控制酷狗音乐 - By FeiYue
;
; 备注:热键可以改为自己喜欢的
;-----------------------------------
*/
#NoEnv
;-- 获取【Acc路径】及其他信息
!F1::
obj:=Acc_GetInfoUnderCursor()
MsgBox, 4096,, % " Path = " obj.Path
. "`n Hwnd = " obj.Hwnd
. "`n Title = " obj.Title
. "`n Class = " obj.Class
. "`n Role = " obj.Role
. "`n Name = " SubStr(obj.Name,1,100)
. "`n Value = " SubStr(obj.Value,1,100)
. "`n State = " obj.State
return
;-- 获取所有【Acc路径】及文本
!F8::
MouseGetPos,,, id
info:={role:"", name:"", value:""}
MsgBox, 4096,, % Clipboard:=Acc_GetAllText(id, info)
return
F2:: 酷狗音乐("上一首")
F3:: 酷狗音乐("下一首")
F4:: 酷狗音乐("播放|暂停")
F5:: 酷狗音乐("我喜欢|取消喜欢")
酷狗音乐(命令)
{
SetBatchLines, -1
SetTitleMatchMode, 2
DetectHiddenWindows, On
WinGet, List, List, 酷狗音乐 ahk_exe KuGou.exe
IfLess, List, 1, return
Loop, % List
{
id:=List%A_Index%
WinGetPos,,, w, h, ahk_id %id%
if (A_Index=1 or w*h>max)
okid:=id, max:=w*h
}
酷狗:={ "上一首" : "4.X.X.14/15.X"
, "播放|暂停" : "4.X.X.14/15.X"
, "下一首" : "4.X.X.14/15.X"
, "我喜欢|取消喜欢" : "4.X.X.13/14.X" }
path:=酷狗[命令], info:={role:0x2B, name:命令, value:""}
if (arr:=Acc_GetObjectFromPath(okid, path, info))
{
Try return arr[1].accDoDefaultAction(arr[2])
}
IfWinExist, ahk_id %okid% ; 后台点击的方法兜底
{
WinGetPos,,, w, h
x:=w//2 + (命令="上一首" ? -70 : 命令="下一首" ? 70 : 0)
y:=h-40
SetControlDelay -1
ControlClick, x%x% y%y%,,,,, NA Pos
}
}
;==================================================
Acc_GetAllText(Acc, info:="", first:=1)
{
static arr, text
SetBatchLines, -1
if (first=1)
{
SendMessage, WM_GETOBJECT:=0x3D, 0, 1,, ahk_id %Acc%
arr:=[], text:="", Acc:=Acc_ObjectFromWindow(Acc, 0)
}
arr.Push(0)
For i, child in Acc_Children(Acc)
{
arr[arr.length()]++, path:=""
Loop, % arr.length()
path.=(A_Index=1 ? "" : ".") . arr[A_Index]
j:=IsObject(child), Role:=Name:=Value:=""
Try Role:=(j ? child.accRole(0) : Acc.accRole(child))
Try Name:=(j ? child.accName(0) : Acc.accName(child))
Try Value:=(j ? child.accValue(0) : Acc.accValue(child))
(!j && path:=RegExReplace(path, "(\w+)$", "c$1"))
if (!info.role||Role=info.role)
&& (!info.name||Name~=info.name)
&& (!info.value||Value~=info.value)
text.=path " ---- " Acc_GetRoleText(Role) " "
. Format("0x{:X}",Role) " [" SubStr(Name,1,100)
. "][" SubStr(Value,1,100) "]`r`n"
if (j)
Acc_GetAllText(child, info, 0)
}
arr.Pop()
if (first=1)
return (s:=text, text:="") ? s:s
}
Acc_GetObjectFr

3168

被折叠的 条评论
为什么被折叠?



