Acc库以及一些使用方法

 

  1. ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=40615
  2. ; 2021.12.11 - 适配当天微信PC版的最新版本:3.4.5.27版本
  3. ; 2022.8.3 - 适配当天微信PC版的最新版本:3.7.5.23版本【将微信窗口最小化可以后台接收】
  4. #SingleInstance Force
  5. SetBatchLines -1
  6. ; 当前列表的第一个用户的最后一条信息
  7. F1::
  8. oAcc := Acc_Get("Object", "4.1.2.2.2.1.1.1.1.1.1.2.2", 0, "微信")
  9. MsgBox % oAcc.accName(1)
  10. return
  11. F2:: ; 遍历微信当前对话内容
  12. oAcc := Acc_Get("Object", "4.1.2.3.1.1.1.1.2.1.1.1", 0, "微信")
  13. 当前对话内容:=""
  14. Loop {
  15. 当前对话内容 .= oAcc.accName(A_Index) "`n"
  16. if (oAcc.accName(A_Index)="")
  17. Break
  18. }
  19. MsgBox % "遍历微信当前对话内容:`n`n" 当前对话内容
  20. MsgBox % "可指定顺序编号:`n`n" oAcc.accName(1) "`n" oAcc.accName(2) "`n" oAcc.accName(3) "`n" oAcc.accName(4)
  21. return
  22. ; 绝对坐标取ACC文字【左上角坐标55,55没有遮挡的话,就会读取到桌面图标名称】
  23. F3::
  24. oAcc := Acc_ObjectFromPoint("", 55, 55)
  25. MsgBox % oAcc.accName(1) "|" oAcc.accName(2) "|" oAcc.accName(3) "|" oAcc.accName(4)
  26. return
  27. F4:: ; 遍历当前窗口的所有项和取指定控件【示例测试请鼠标对准,自带记事本】
  28. WinGet, hWnd, ID, A
  29. MsgBox % Clipboard := JEE_AccGetTextAll(hWnd, "`r`n")
  30. ; ============== 以下是针对自带记事本生效 ==============
  31. ;编辑控制信息是: 4.1.4
  32. ;读取路径将是 4.1.4
  33. ;而我们将用0 accValue()
  34. oAcc := Acc_Get("Object", "4.1.4", 0, "ahk_id " hWnd)
  35. MsgBox % oAcc.accValue(0)
  36. ;状态栏信息是: 4.2.4 c2
  37. ;读取路径将是 4.2.4
  38. ;而我们将用2 accName()
  39. oAcc := Acc_Get("Object", "4.2.4", 0, "ahk_id " hWnd)
  40. MsgBox % oAcc.accName(2)
  41. return
  42. F6:: ; 点击记事本的编辑按钮【accDoDefaultAction()应该只适用于标准控件,不是一定有效】[自测微信QQ都不行]
  43. ; WinActivate, ahk_class Notepad
  44. oAcc := Acc_Get("Object", "3.2", 0, "ahk_class Notepad")
  45. Try oAcc.accDoDefaultAction() ; 单击目标控件
  46. return
  47. F7:: ; 系统自带记事本 - 获取ACC信息(控件)
  48. ControlGet, hCtl1, hWnd,, Edit1, ahk_class Notepad
  49. ControlGet, hCtl2, hWnd,, msctls_statusbar321, ahk_class Notepad
  50. MsgBox % Clipboard := JEE_AccGetTextAll(hCtl1, "`r`n")
  51. MsgBox % Clipboard := JEE_AccGetTextAll(hCtl2, "`r`n")
  52. ;编辑控制信息是: 4
  53. ;读取路径将是 4
  54. ;而我们将用0 accValue()
  55. oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl1)
  56. MsgBox % oAcc.accValue(0)
  57. ;状态栏信息是: 4 c2
  58. ;读取路径将是 4
  59. ;而我们将用2 accName()
  60. oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl2)
  61. MsgBox % oAcc.accName(2)
  62. return
  63. ;==================================================
  64. ; ;e.g.
  65. ; 1::
  66. ; WinGet, hWnd, ID, A
  67. ; MsgBox % Clipboard := JEE_AccGetTextAll(hWnd, "`r`n")
  68. ; return
  69. ; ;e.g.
  70. ; 2::
  71. ; ControlGet, hCtl, Hwnd,, Edit1, A
  72. ; MsgBox % Clipboard := JEE_AccGetTextAll(hCtl, "`r`n")
  73. ; return
  74. ; ;e.g.
  75. ; 3::
  76. ; ControlGetFocus, vCtlClassNN, A
  77. ; ControlGet, hCtl, Hwnd,, % vCtlClassNN, A
  78. ; MsgBox % Clipboard := JEE_AccGetTextAll(hCtl, "`r`n")
  79. ; return
  80. ;vOpt: 以空格分隔的列表
  81. ;vOpt: n#: e.g. n20 ; 将检索名称限制在前20个字符
  82. ;vOpt: v#: e.g. v20 ; 限制检索值为前20个字符
  83. JEE_StrRept(vText, vNum) {
  84. if (vNum <= 0)
  85. return
  86. return StrReplace(Format("{:" vNum "}", ""), " ", vText)
  87. ;return StrReplace(Format("{:0" vNum "}", 0), 0, vText)
  88. }
  89. JEE_AccGetTextAll(hWnd:=0, vSep:="`n", vIndent:="`t", vOpt:="")
  90. {
  91. vLimN := 20, vLimV := 20
  92. Loop, Parse, vOpt, % " "
  93. {
  94. vTemp := A_LoopField
  95. if (SubStr(vTemp, 1, 1) = "n")
  96. vLimN := SubStr(vTemp, 2)
  97. else if (SubStr(vTemp, 1, 1) = "v")
  98. vLimV := SubStr(vTemp, 2)
  99. }
  100. oMem := {}, oPos := {}
  101. ;OBJID_WINDOW := 0x0
  102. oMem[1, 1] := Acc_ObjectFromWindow(hWnd, 0x0)
  103. oPos[1] := 1, vLevel := 1
  104. VarSetCapacity(vOutput, 1000000*2)
  105. Loop
  106. {
  107. if !vLevel
  108. break
  109. if !oMem[vLevel].HasKey(oPos[vLevel])
  110. {
  111. oMem.Delete(vLevel)
  112. oPos.Delete(vLevel)
  113. vLevelLast := vLevel, vLevel -= 1
  114. oPos[vLevel]++
  115. continue
  116. }
  117. oKey := oMem[vLevel, oPos[vLevel]]
  118. vName := "", vValue := ""
  119. if IsObject(oKey)
  120. {
  121. vRoleText := Acc_GetRoleText(oKey.accRole(0))
  122. try vName := oKey.accName(0)
  123. try vValue := oKey.accValue(0)
  124. }
  125. else
  126. {
  127. oParent := oMem[vLevel-1,oPos[vLevel-1]]
  128. vChildId := IsObject(oKey) ? 0 : oPos[vLevel]
  129. vRoleText := Acc_GetRoleText(oParent.accRole(vChildID))
  130. try vName := oParent.accName(vChildID)
  131. try vValue := oParent.accValue(vChildID)
  132. }
  133. if (StrLen(vName) > vLimN)
  134. vName := SubStr(vName, 1, vLimN) "..."
  135. if (StrLen(vValue) > vLimV)
  136. vValue := SubStr(vValue, 1, vLimV) "..."
  137. vName := RegExReplace(vName, "[`r`n]", " ")
  138. vValue := RegExReplace(vValue, "[`r`n]", " ")
  139. vAccPath := ""
  140. if IsObject(oKey)
  141. {
  142. Loop, % oPos.Length() - 1
  143. vAccPath .= (A_Index=1?"":".") oPos[A_Index+1]
  144. }
  145. else
  146. {
  147. Loop, % oPos.Length() - 2
  148. vAccPath .= (A_Index=1?"":".") oPos[A_Index+1]
  149. vAccPath .= " c" oPos[oPos.Length()]
  150. }
  151. vOutput .= vAccPath "`t" JEE_StrRept(vIndent, vLevel-1) vRoleText " [" vName "][" vValue "]" vSep
  152. oChildren := Acc_Children(oKey)
  153. if !oChildren.Length()
  154. oPos[vLevel]++
  155. else
  156. {
  157. vLevelLast := vLevel, vLevel += 1
  158. oMem[vLevel] := oChildren
  159. oPos[vLevel] := 1
  160. }
  161. }
  162. return SubStr(vOutput, 1, -StrLen(vSep))
  163. }
  164. ;----------------------------------------------------------------------------------------------------------------------
  165. ; Acc.ahk
  166. ;----------------------------------------------------------------------------------------------------------------------
  167. ; Authors (dd/mm/yyyy):
  168. ; Sean ()
  169. ; jethrow (19/02/2012)
  170. ; Sancarn (26/11/2017,18/01/2019,10/05/2019)
  171. ;----------------------------------------------------------------------------------------------------------------------
  172. ; CHANGE LOG:
  173. ;----------------------------------------------------------------------------------------------------------------------
  174. ;19/02/2012:
  175. ; Modified ComObjEnwrap params from (9,pacc) --> (9,pacc,1)
  176. ; Changed ComObjUnwrap to ComObjValue in order to avoid AddRef (thanks fincs)
  177. ; Added Acc_GetRoleText & Acc_GetStateText
  178. ; Added additional functions - commented below
  179. ; Removed original Acc_Children function
  180. ;26/11/2017:
  181. ; Added Enumerations as Objects
  182. ; Added IAccessible walking functionality e.g.
  183. ; acc_childrenFilter(oAcc, ACC_FILTERS.byDescription, "Amazing button")
  184. ;
  185. ; acc_childrenFilter(oAcc, Func("myAwesomeFunction"), true)
  186. ; myAwesomeFunction(oAcc,val){
  187. ; return val
  188. ; }
  189. ; Added Acc_ChildProxy to Acc_Children
  190. ;18/01/2019:
  191. ; Documentation Update
  192. ;10/05/2019:
  193. ; Error Checking to ACC_ChildProxy
  194. ;----------------------------------------------------------------------------------------------------------------------
  195. ;ACC INTELLISENSE PACK:
  196. ;----------------------------------------------------------------------------------------------------------------------
  197. ;IACC成员属性:[ACCCHILDACCHECHEDCOUNTACCDEFAULTIACTACCDESICRINGACCOCUSACCHELPACCHELPTOPICACCKEYBOARDSHORTCUTACCNAMEACCPLENTACCROLEACCSELECTIONACTATEACCVALUE]
  198. ;成员方法:[AccDodefaultActionAcchittestAcclimationAccNavateAccSelect]
  199. ;全局常量:[acc_navdiracc_selectionflagacc_eventvt_constantsacc_filtersacc_objidAcc_StateAcc_Role]
  200. ;全局方法:[Acc_ObjectFroomEventAcc_ObjectFromoPoptAcc_ObjectFromWindowAcc_WindowFromObjectAcc_SetWineventhookAcc_LockWineventAcc_LocationAcc_ParentAcc_ChildAcc_ChildrenAcc_GetAcc_ChildrenFilterAcc_GetRootElement
  201. ;
  202. ;----------------------------------------------------------------------------------------------------------------------
  203. ; DOCUMENTATION:
  204. ;----------------------------------------------------------------------------------------------------------------------
  205. ; IACC成员属性:
  206. ;如果存在,则为指定子项速写读取idispatch界面,如果存在。所有对象都必须支持此属性。请参阅get_accchild
  207. ; acchildcount只读属于此对象的子项数。所有对象都必须支持此属性。请参阅get_accchildcount
  208. ; AccDefaultAction只读一个描述对象默认操作的字符串。并非所有对象都有默认操作。请参阅get_accdefaultaction
  209. ; AccDescription Read-one Lotup To In Automation的转换中不支持ACCDescription属性。 Microsoft Active Accessibility服务器和应用程序不应使用它。一个字符串,用于描述指定对象的可视化外观。并非所有对象都有描述。
  210. ; ACCFOCUS只读具有键盘焦点的对象。接收键盘焦点的所有对象都必须支持此属性。请参阅get_accfocus
  211. ; Acchelp只读一个帮助字符串。并非所有对象都支持此属性。请参阅get_acchelp
  212. ; acchelptopic只读注意弃用了acchelptopic属性,不应使用。与指定对象相关联的帮助文件和该文件中相应主题的标识符的完整路径。并非所有对象都支持此属性。
  213. ; Acckeyboardshortcut只读对象的快捷键或访问密钥,也称为助记符。所有具有快捷键或访问密钥的对象都支持此属性。请参阅get_acckeyboardshortcut
  214. ; accName只读对象的名称。所有对象都支持此属性。请参阅get_accname
  215. ; ACCALTENT只读对象父级的IDISPATCH接口。所有对象都支持此属性。见get_accparent
  216. ; accrole可读信息,用于描述指定对象的角色。所有对象都支持此属性。见get_accrole
  217. ; Accselection只读此对象的所选子项。支持选择的所有对象必须支持此属性。请参阅get_accselection
  218. ; acctate只读对象的当前状态。所有对象都支持此属性。请参阅get_accstate
  219. ; accvalue读/写对象的值。并非所有对象都有一个值。请参阅get_accvalueput_accvalue
  220. ;会员方法:
  221. ; AccDodeFaultAction执行指定的对象的默认操作。并非所有对象都有默认操作。
  222. ; Acchittest在屏幕上的给定点处检索子元素或子对象。所有可视对象都支持此方法。
  223. ; acclocation检索指定的对象的当前屏幕位置。所有可视对象都支持此方法。
  224. ;ACCNAVAVAVAGE注意弃用了ACCNAVAVAIGE方法,不应使用。客户端应该使用其他方法和属性,如accessiblechildrenget_accchildget_accparentienumvariant。遍历容器中的另一个用户界面元素并检索对象。所有可视对象都支持此方法。
  225. ; AccSelect修改了选择或移动指定对象的键盘焦点。支持选择或接收键盘焦点的所有对象都必须支持此方法。
  226. ;全球常量:
  227. ; ACC_NAVDIR对象包含不同的导航方向标志。
  228. ; ACC_SELETIONFLAG对象包含不同的ACCSELECT()标志。
  229. ; ACC_Event对象包含可以与Acc_ObjectFroomEvent一起使用的不同Windows事件。
  230. ; VT_Constants对象包含不同的COM VTABLE常量。
  231. ; ACC_FILERNS包含要与ACC_CHILDRENFILT一起使用的过滤器函数的对象。
  232. ; ACC_OBID对象包含不同的对象名称和ID
  233. ; ACC_STATE对象包含不同的状态名称和ID
  234. ; ACC_ROLE对象包含不同的角色名称和ID
  235. ;全球方法:
  236. ; Acc_ObjectFroomEventByRef _idChild_HWNDIDObjectIDChild - 用于从事件中获取ACC对象
  237. ; ACC_OBJECTFOLPOINTBYREF _IDCHILD_ =“”,x =“”,y =“”) - 用于从xy点获取ACC对象
  238. ; Acc_ObjectFromWindowHWNDIDObject = -4 - 用于从HWND获取ACC对象
  239. ; Acc_WindowFromObjectPACC - 用于从ACC对象获取HWND
  240. ; Acc_SetWineventhookEventminEventMaxPCallback - 侦听Windows事件。使用ACC对象Param致电回调​​。
  241. ; ACC_UNHOOKWINEVENTHHOK - 停止收听现有事件钩。
  242. ; ACC_LOCATIONACCChildID = 0 - 获取IACIBESSIBLEVENT的位置
  243. ; ACC_ParentACC - 获取元素的父对象
  244. ; ACC_CHILDACCCHILDID = 0 - 使用指定的ID获取对象的子项。
  245. ; ACC_CHILDRENACC - 获取IACICESTIBLEVENT的子项(作为阵列)
  246. ; ACC_GETCMDCHILDPATH =“”,CHILDID = 0WINTITLE =“”“,WINTEXT =”“,”excludeTITLE =“”,“excludeText =”“) - 获取可访问的对象
  247. ; ACC_CHILDRENFILTEROACCFConditionValue = 0RetrateOne = FalseOBJ = 0 - 过滤子子通过某些定义的条件
  248. ; Acc_GetRootElement() - 返回桌面的ACC对象(所有ACC树元素的根目录)
  249. ;弃用和内部方法:
  250. ; ACC_INIT() - 不要打电话!
  251. ; Acc_QueryACC - 不要打电话!从对象查询iAccessible接口
  252. ; Acc_Errorp =“”) - 不要打电话!错误信息
  253. ; ACC_GETROLETEXTNROLE - [已弃用。使用ACC_ROLE对象] GET'S ACC角色作为文本。
  254. ; Acc_GetStateText(nstate) - [已弃用。使用ACC_STATE对象] GET'S ACC状态为文本。
  255. ; ACC_ROLEACCChildID = 0 - [已弃用。使用Acc_Role对象]
  256. ; ACC_STATEACCCHILDID = 0 - [已弃用。使用ACC_STATE对象]
  257. ; Acc_ChildrenByroleACC,角色) - [已弃用。使用ACC_CHILDRENFILTER]获取指定角色的所有孩子。
  258. ; ACC_CHILDRENBYNAMEOCACESSIBLENAMERETURNONE = FALSE - [已弃用。使用Acc_ChildrenFilter]按名称过滤子名称,如果returnone那么只返回1个孩子
  259. ;
  260. ;----------------------------------------------------------------------------------------------------------------------
  261. ;进一步描述:
  262. ;----------------------------------------------------------------------------------------------------------------------
  263. ; Acc_ChildrenFilter.
  264. ;过滤在ACC对象中的子项,并调用2nd参数与ACC对象和第3参数定义的函数。
  265. ;如果函数返回true,则将孩子包含在过滤器中。
  266. ;例子:
  267. ;以下函数将包括基于第3个参数的子项:
  268. ; ACC_CHILDRENFILTEROACCFUNC(“MYAWESOMEFUNCT”),真实);返回所有孩子
  269. ; ACC_CHILDRENFILTEROACCFUNC(“MYAWESOMEFUNCT”),真实);没有孩子
  270. ; myawesomefunctionoaccval){
  271. ;返回val.
  272. ; }
  273. ;
  274. ; Acc_Filters.
  275. ;这些通常与`Acc_Childrenfilter`结合使用:
  276. ;例子:
  277. ; ACC_CHILDRENFILTEROACCACC_FILTERS.BYDESCRIPTION,“Amazing Button”)
  278. ;辅助方法列表:
  279. ; Acc_Filters.ByDefaultActionOACCAction - 通过特定的默认操作过滤子项
  280. ; Acc_Filters.ByDescriptionOACCDESC - 通过特定描述过滤子项
  281. ; ACC_FILTERS.BYVALUEOACCVALUE - 通过特定值过滤子项
  282. ; ACC_FILTERS.BYHELPOACCHLPTXT - 通过特定的帮助文本过滤子项
  283. ; Acc_Filters.ByStateOACC,状态) - 通过特定状态过滤子项
  284. ; ACC_FILTERS.BYROLEOACC,角色) - 通过特定角色过滤子项
  285. ; ACC_FILTERS.BYNAMEOACCNAME - 通过特定名称过滤子项
  286. ; ACC_FILTERS.BYGEXOACCREGEX - 通过REGEX匹配对阵字符串的筛选子项:%accName%;%accHelp%;%accValue%;%accDescription%;%accDefaultAction%
  287. ;----------------------------------------------------------------------------------------------------------------------
  288. ;https://msdn.microsoft.com/en-us/library/windows/desktop/dd373606(v=vs.85).aspx
  289. class ACC_OBJID{
  290. static WINDOW := 0x00000000
  291. static SYSMENU := 0xFFFFFFFF
  292. static TITLEBAR := 0xFFFFFFFE
  293. static MENU := 0xFFFFFFFD
  294. static CLIENT := 0xFFFFFFFC
  295. static VSCROLL := 0xFFFFFFFB
  296. static HSCROLL := 0xFFFFFFFA
  297. static SIZEGRIP := 0xFFFFFFF9
  298. static CARET := 0xFFFFFFF8
  299. static CURSOR := 0xFFFFFFF7
  300. static ALERT := 0xFFFFFFF6
  301. static SOUND := 0xFFFFFFF5
  302. static QUERYCLASSNAMEIDX := 0xFFFFFFF4
  303. static NATIVEOM := 0xFFFFFFF0
  304. }
  305. ;https://msdn.microsoft.com/en-us/library/windows/desktop/dd373609(v=vs.85).aspx
  306. class ACC_STATE {
  307. static NORMAL := 0
  308. static UNAVAILABLE := 0x1
  309. static SELECTED := 0x2
  310. static FOCUSED := 0x4
  311. static PRESSED := 0x8
  312. static CHECKED := 0x10
  313. static MIXED := 0x20
  314. static INDETERMINATE := this.MIXED
  315. static READONLY := 0x40
  316. static HOTTRACKED := 0x80
  317. static DEFAULT := 0x100
  318. static EXPANDED := 0x200
  319. static COLLAPSED := 0x400
  320. static BUSY := 0x800
  321. static FLOATING := 0x1000
  322. static MARQUEED := 0x2000
  323. static ANIMATED := 0x4000
  324. static INVISIBLE := 0x8000
  325. static OFFSCREEN := 0x10000
  326. static SIZEABLE := 0x20000
  327. static MOVEABLE := 0x40000
  328. static SELFVOICING := 0x80000
  329. static FOCUSABLE := 0x100000
  330. static SELECTABLE := 0x200000
  331. static LINKED := 0x400000
  332. static TRAVERSED := 0x800000
  333. static MULTISELECTABLE := 0x1000000
  334. static EXTSELECTABLE := 0x2000000
  335. static ALERT_LOW := 0x4000000
  336. static ALERT_MEDIUM := 0x8000000
  337. static ALERT_HIGH := 0x10000000
  338. static PROTECTED := 0x20000000
  339. static VALID := 0x7fffffff
  340. }
  341. ;https://msdn.microsoft.com/en-us/library/windows/desktop/dd373608(v=vs.85).aspx
  342. class ACC_ROLE {
  343. static TITLEBAR := 0x1
  344. static MENUBAR := 0x2
  345. static SCROLLBAR := 0x3
  346. static GRIP := 0x4
  347. static SOUND := 0x5
  348. static CURSOR := 0x6
  349. static CARET := 0x7
  350. static ALERT := 0x8
  351. static WINDOW := 0x9
  352. static CLIENT := 0xa
  353. static MENUPOPUP := 0xb
  354. static MENUITEM := 0xc
  355. static TOOLTIP := 0xd
  356. static APPLICATION := 0xe
  357. static DOCUMENT := 0xf
  358. static PANE := 0x10
  359. static CHART := 0x11
  360. static DIALOG := 0x12
  361. static BORDER := 0x13
  362. static GROUPING := 0x14
  363. static SEPARATOR := 0x15
  364. static TOOLBAR := 0x16
  365. static STATUSBAR := 0x17
  366. static TABLE := 0x18
  367. static COLUMNHEADER := 0x19
  368. static ROWHEADER := 0x1a
  369. static COLUMN := 0x1b
  370. static ROW := 0x1c
  371. static CELL := 0x1d
  372. static LINK := 0x1e
  373. static HELPBALLOON := 0x1f
  374. static CHARACTER := 0x20
  375. static LIST := 0x21
  376. static LISTITEM := 0x22
  377. static OUTLINE := 0x23
  378. static OUTLINEITEM := 0x24
  379. static PAGETAB := 0x25
  380. static PROPERTYPAGE := 0x26
  381. static INDICATOR := 0x27
  382. static GRAPHIC := 0x28
  383. static STATICTEXT := 0x29
  384. static TEXT := 0x2a
  385. static PUSHBUTTON := 0x2b
  386. static CHECKBUTTON := 0x2c
  387. static RADIOBUTTON := 0x2d
  388. static COMBOBOX := 0x2e
  389. static DROPLIST := 0x2f
  390. static PROGRESSBAR := 0x30
  391. static DIAL := 0x31
  392. static HOTKEYFIELD := 0x32
  393. static SLIDER := 0x33
  394. static SPINBUTTON := 0x34
  395. static DIAGRAM := 0x35
  396. static ANIMATION := 0x36
  397. static EQUATION := 0x37
  398. static BUTTONDROPDOWN := 0x38
  399. static BUTTONMENU := 0x39
  400. static BUTTONDROPDOWNGRID := 0x3a
  401. static WHITESPACE := 0x3b
  402. static PAGETABLIST := 0x3c
  403. static CLOCK := 0x3d
  404. static SPLITBUTTON := 0x3e
  405. static IPADDRESS := 0x3f
  406. static OUTLINEBUTTON := 0x40
  407. }
  408. ;https://msdn.microsoft.com/en-us/library/windows/desktop/dd373600(v=vs.85).aspx
  409. class ACC_NAVDIR {
  410. static MIN := 0x0
  411. static UP := 0x1
  412. static DOWN := 0x2
  413. static LEFT := 0x3
  414. static RIGHT := 0x4
  415. static NEXT := 0x5
  416. static PREVIOUS := 0x6
  417. static FIRSTCHILD := 0x7
  418. static LASTCHILD := 0x8
  419. static MAX := 0x9
  420. }
  421. ;https://msdn.microsoft.com/en-us/library/windows/desktop/dd373634(v=vs.85).aspx
  422. class ACC_SELECTIONFLAG {
  423. static NONE := 0x0
  424. static TAKEFOCUS := 0x1
  425. static TAKESELECTION := 0x2
  426. static EXTENDSELECTION := 0x4
  427. static ADDSELECTION := 0x8
  428. static REMOVESELECTION := 0x10
  429. static VALID := 0x1f
  430. }
  431. ;MSAA Events list:
  432. ; https://msdn.microsoft.com/en-us/library/windows/desktop/dd318066(v=vs.85).aspx
  433. ;What are win events:
  434. ; https://msdn.microsoft.com/en-us/library/windows/desktop/dd373868(v=vs.85).aspx
  435. ;System-Level and Object-level events:
  436. ; https://msdn.microsoft.com/en-us/library/windows/desktop/dd373657(v=vs.85).aspx
  437. ;Console accessibility:
  438. ; https://msdn.microsoft.com/en-us/library/ms971319.aspx
  439. class ACC_EVENT {
  440. static MIN := 0x00000001
  441. static MAX := 0x7FFFFFFF
  442. static SYSTEM_SOUND := 0x0001
  443. static SYSTEM_ALERT := 0x0002
  444. static SYSTEM_FOREGROUND := 0x0003
  445. static SYSTEM_MENUSTART := 0x0004
  446. static SYSTEM_MENUEND := 0x0005
  447. static SYSTEM_MENUPOPUPSTART := 0x0006
  448. static SYSTEM_MENUPOPUPEND := 0x0007
  449. static SYSTEM_CAPTURESTART := 0x0008
  450. static SYSTEM_CAPTUREEND := 0x0009
  451. static SYSTEM_MOVESIZESTART := 0x000A
  452. static SYSTEM_MOVESIZEEND := 0x000B
  453. static SYSTEM_CONTEXTHELPSTART := 0x000C
  454. static SYSTEM_CONTEXTHELPEND := 0x000D
  455. static SYSTEM_DRAGDROPSTART := 0x000E
  456. static SYSTEM_DRAGDROPEND := 0x000F
  457. static SYSTEM_DIALOGSTART := 0x0010
  458. static SYSTEM_DIALOGEND := 0x0011
  459. static SYSTEM_SCROLLINGSTART := 0x0012
  460. static SYSTEM_SCROLLINGEND := 0x0013
  461. static SYSTEM_SWITCHSTART := 0x0014
  462. static SYSTEM_SWITCHEND := 0x0015
  463. static SYSTEM_MINIMIZESTART := 0x0016
  464. static SYSTEM_MINIMIZEEND := 0x0017
  465. static CONSOLE_CARET := 0x4001
  466. static CONSOLE_UPDATE_REGION := 0x4002
  467. static CONSOLE_UPDATE_SIMPLE := 0x4003
  468. static CONSOLE_UPDATE_SCROLL := 0x4004
  469. static CONSOLE_LAYOUT := 0x4005
  470. static CONSOLE_START_APPLICATION := 0x4006
  471. static CONSOLE_END_APPLICATION := 0x4007
  472. static OBJECT_CREATE := 0x8000
  473. static OBJECT_DESTROY := 0x8001
  474. static OBJECT_SHOW := 0x8002
  475. static OBJECT_HIDE := 0x8003
  476. static OBJECT_REORDER := 0x8004
  477. static OBJECT_FOCUS := 0x8005
  478. static OBJECT_SELECTION := 0x8006
  479. static OBJECT_SELECTIONADD := 0x8007
  480. static OBJECT_SELECTIONREMOVE := 0x8008
  481. static OBJECT_SELECTIONWITHIN := 0x8009
  482. static OBJECT_STATECHANGE := 0x800A
  483. static OBJECT_LOCATIONCHANGE := 0x800B
  484. static OBJECT_NAMECHANGE := 0x800C
  485. static OBJECT_DESCRIPTIONCHANGE := 0x800D
  486. static OBJECT_VALUECHANGE := 0x800E
  487. static OBJECT_PARENTCHANGE := 0x800F
  488. static OBJECT_HELPCHANGE := 0x8010
  489. static OBJECT_DEFACTIONCHANGE := 0x8011
  490. static OBJECT_ACCELERATORCHANGE := 0x8012
  491. }
  492. class VT_CONSTANTS {
  493. static EMPTY := 0x0 ; No value
  494. static NULL := 0x1 ; SQL-style Null
  495. static I2 := 0x2 ; 16-bit signed int
  496. static I4 := 0x3 ; 32-bit signed int
  497. static R4 := 0x4 ; 32-bit floating-point number
  498. static R8 := 0x5 ; 64-bit floating-point number
  499. static CY := 0x6 ; Currency
  500. static DATE := 0x7 ; Date
  501. static BSTR := 0x8 ; COM string (Unicode string with length prefix)
  502. static DISPATCH := 0x9 ; COM object
  503. static ERROR := 0xA ; Error code (32-bit integer)
  504. static BOOL := 0xB ; Boolean True (-1) or False (0)
  505. static VARIANT := 0xC ; VARIANT (must be combined with VT_ARRAY or VT_BYREF)
  506. static UNKNOWN := 0xD ; IUnknown interface pointer
  507. static DECIMAL := 0xE ; (not supported)
  508. static I1 := 0x10 ; 8-bit signed int
  509. static UI1 := 0x11 ; 8-bit unsigned int
  510. static UI2 := 0x12 ; 16-bit unsigned int
  511. static UI4 := 0x13 ; 32-bit unsigned int
  512. static I8 := 0x14 ; 64-bit signed int
  513. static UI8 := 0x15 ; 64-bit unsigned int
  514. static INT := 0x16 ; Signed machine int
  515. static UINT := 0x17 ; Unsigned machine int
  516. static RECORD := 0x24 ; User-defined type -- NOT SUPPORTED
  517. static ARRAY := 0x2000 ; SAFEARRAY
  518. static BYREF := 0x4000 ; Pointer to another type of value
  519. }
  520. class ACC_FILTERS {
  521. byDefaultAction(oAcc,action){
  522. b := oAcc.accDefaultAction = action
  523. return b
  524. }
  525. byDescription(oAcc,desc){
  526. b := oAcc.accDescription = desc
  527. return b
  528. }
  529. byValue(oAcc,value){
  530. b := oAcc.accValue = value
  531. return b
  532. }
  533. byHelp(oAcc,help){
  534. b := oAcc.accHelp = help
  535. }
  536. byState(oAcc,state){
  537. return oAcc.accState & state
  538. }
  539. byRole(oAcc,role){
  540. b := oAcc.accRole = role
  541. return b
  542. }
  543. byName(oAcc,name){
  544. b := oAcc.accName = name
  545. return b
  546. }
  547. byRegex(oAcc,rx){
  548. info := oAcc.accName . ";"
  549. . oAcc.accHelp . ";"
  550. . oAcc.accValue ";"
  551. . oAcc.accDescription . ";"
  552. . oAcc.accDefaultAction
  553. return RegexMatch(Haystack, rx) > 0
  554. }
  555. }
  556. Acc_Init()
  557. {
  558. Static h := DllCall("LoadLibrary","Str","oleacc","Ptr")
  559. }
  560. Acc_ObjectFromEvent(ByRef _idChild_, hWnd, idObject, idChild)
  561. {
  562. Acc_Init()
  563. if (DllCall("oleacc\AccessibleObjectFromEvent"
  564. , "Ptr", hWnd
  565. , "UInt", idObject
  566. , "UInt", idChild
  567. , "Ptr*", pacc
  568. , "Ptr", VarSetCapacity(varChild, 8 + 2 * A_PtrSize, 0) * 0 + &varChild) = 0) {
  569. _idChild_:=NumGet(varChild,8,"UInt")
  570. return ComObjEnwrap(9,pacc,1)
  571. }
  572. }
  573. Acc_ObjectFromPoint(ByRef _idChild_ = "", x = "", y = "")
  574. {
  575. Acc_Init()
  576. if (DllCall("oleacc\AccessibleObjectFromPoint"
  577. , "Int64", x == ""||y==""
  578. ? 0 * DllCall("GetCursorPos","Int64*",pt) + pt
  579. : x & 0xFFFFFFFF | y << 32
  580. , "Ptr*", pacc
  581. , "Ptr", VarSetCapacity(varChild, 8 + 2 * A_PtrSize, 0) * 0 + &varChild) = 0) {
  582. _idChild_:=NumGet(varChild,8,"UInt")
  583. return ComObjEnwrap(9,pacc,1)
  584. }
  585. }
  586. Acc_ObjectFromWindow(hWnd, idObject = -4)
  587. {
  588. Acc_Init()
  589. if (DllCall("oleacc\AccessibleObjectFromWindow"
  590. , "Ptr", hWnd
  591. , "UInt", idObject &= 0xFFFFFFFF
  592. , "Ptr", -VarSetCapacity(IID,16)
  593. + NumPut(idObject == 0xFFFFFFF0
  594. ? 0x46000000000000C0
  595. : 0x719B3800AA000C81
  596. , NumPut(idObject == 0xFFFFFFF0
  597. ? 0x0000000000020400
  598. : 0x11CF3C3D618736E0,IID,"Int64"),"Int64")
  599. , "Ptr*", pacc) = 0)
  600. return ComObjEnwrap(9,pacc,1)
  601. }
  602. Acc_WindowFromObject(pacc)
  603. {
  604. if (DllCall("oleacc\WindowFromAccessibleObject"
  605. , "Ptr", IsObject(pacc) ? ComObjValue(pacc) : pacc
  606. , "Ptr*", hWnd) = 0)
  607. return hWnd
  608. }
  609. ;Implement this?
  610. ; IAccessibleHandler::AccessibleObjectFromID
  611. Acc_GetRoleText(nRole)
  612. {
  613. nSize := DllCall("oleacc\GetRoleText"
  614. , "Uint", nRole
  615. , "Ptr", 0
  616. , "Uint", 0)
  617. VarSetCapacity(sRole, (A_IsUnicode ? 2 : 1) * nSize)
  618. DllCall("oleacc\GetRoleText"
  619. , "Uint", nRole
  620. , "str", sRole
  621. , "Uint", nSize+1)
  622. return sRole
  623. }
  624. Acc_GetStateText(nState)
  625. {
  626. nSize := DllCall("oleacc\GetStateText"
  627. , "Uint", nState
  628. , "Ptr", 0
  629. , "Uint", 0)
  630. VarSetCapacity(sState, (A_IsUnicode ? 2 : 1) * nSize)
  631. DllCall("oleacc\GetStateText"
  632. , "Uint", nState
  633. , "str", sState
  634. , "Uint", nSize+1)
  635. return sState
  636. }
  637. Acc_SetWinEventHook(eventMin, eventMax, pCallback)
  638. {
  639. Return DllCall("SetWinEventHook", "Uint", eventMin, "Uint", eventMax, "Uint", 0, "Ptr", pCallback, "Uint", 0, "Uint", 0, "Uint", 0)
  640. }
  641. Acc_UnhookWinEvent(hHook)
  642. {
  643. Return DllCall("UnhookWinEvent", "Ptr", hHook)
  644. }
  645. /* Win Events:
  646. pCallback := RegisterCallback("WinEventProc")
  647. WinEventProc(hHook, event, hWnd, idObject, idChild, eventThread, eventTime)
  648. {
  649. Critical
  650. Acc := Acc_ObjectFromEvent(_idChild_, hWnd, idObject, idChild)
  651. ; Code Here:
  652. }
  653. */
  654. ; Written by jethrow
  655. Acc_Role(Acc, ChildId=0) {
  656. try return ComObjType(Acc,"Name") = "IAccessible"
  657. ? Acc_GetRoleText(Acc.accRole(ChildId))
  658. : "invalid object"
  659. }
  660. Acc_State(Acc, ChildId=0) {
  661. try return ComObjType(Acc,"Name") = "IAccessible"
  662. ? Acc_GetStateText(Acc.accState(ChildId))
  663. : "invalid object"
  664. }
  665. Acc_Location(Acc, ChildId=0) { ; adapted from Sean's code
  666. try Acc.accLocation(ComObj(0x4003, & x := 0)
  667. , ComObj(0x4003,&y:=0)
  668. , ComObj(0x4003,&w:=0)
  669. , ComObj(0x4003,&h:=0)
  670. , ChildId)
  671. catch
  672. return
  673. return { x:NumGet(x,0,"int")
  674. , y:NumGet(y,0,"int")
  675. , w:NumGet(w,0,"int")
  676. , h:NumGet(h,0,"int")
  677. , pos:"x" NumGet(x,0,"int")
  678. . " y" NumGet(y,0,"int")
  679. . " w" NumGet(w,0,"int")
  680. . " h" NumGet(h,0,"int") }
  681. }
  682. Acc_Parent(Acc) {
  683. try parent := Acc.accParent
  684. return parent ? Acc_Query(parent) :
  685. }
  686. Acc_Child(Acc, ChildId=0) {
  687. try child := Acc.accChild(ChildId)
  688. return child ? Acc_Query(child) :
  689. }
  690. ; thanks Lexikos - www.autohotkey.com/forum/viewtopic.php?t=81731&p=509530#509530
  691. Acc_Query(Acc) {
  692. try return ComObj(9, ComObjQuery(Acc, "{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
  693. }
  694. ;Acc_GetChild(Acc_or_Hwnd, child_path) {
  695. ; Acc := WinExist("ahk_id" Acc_or_Hwnd)? Acc_ObjectFromWindow(Acc_or_Hwnd):Acc_or_Hwnd
  696. ; if ComObjType(Acc,"Name") = "IAccessible" {
  697. ; Loop Parse, child_path, csv
  698. ; Acc := A_LoopField="P"? Acc_Parent(Acc):Acc_Children(Acc)[A_LoopField]
  699. ; return Acc
  700. ; }
  701. ;}
  702. Acc_Error(p="") {
  703. static setting:=0
  704. return p=""?setting:setting:=p
  705. }
  706. Acc_Children(Acc) {
  707. if ComObjType(Acc,"Name") != "IAccessible"
  708. ErrorLevel := "Invalid IAccessible Object"
  709. else {
  710. Acc_Init(), cChildren:=Acc.accChildCount, Children:=[], ErrorLevel=
  711. 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 {
  712. Loop %cChildren%
  713. {
  714. i:=(A_Index-1)*(A_PtrSize*2+8)+8
  715. child:=NumGet(varChildren,i)
  716. ;I assume NumGet(varChildren,i-8) is ComObjType ~Sancarn
  717. ComType := NumGet(varChildren,i-8)
  718. if (ComType = VT_CONSTANTS.DISPATCH) {
  719. Children.push(Acc_Query(child))
  720. ObjRelease(child)
  721. } else if (ComType = VT_CONSTANTS.I4) {
  722. Children.push(new ACC_ChildProxy(Acc,child))
  723. } else {
  724. ErrorLevel := "Unknown ComType: " ComType
  725. Children.push(child)
  726. }
  727. }
  728. return Children.MaxIndex()?Children:
  729. } else
  730. ErrorLevel := "AccessibleChildren DllCall Failed"
  731. }
  732. if Acc_Error()
  733. throw Exception(ErrorLevel,-1)
  734. }
  735. Acc_ChildrenByRole(Acc, Role) {
  736. if ComObjType(Acc,"Name")!="IAccessible"
  737. ErrorLevel := "Invalid IAccessible Object"
  738. else {
  739. Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]
  740. 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 {
  741. Loop %cChildren% {
  742. i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i)
  743. if NumGet(varChildren,i-8)=9
  744. AccChild:=Acc_Query(child), ObjRelease(child), Acc_Role(AccChild)=Role?Children.Insert(AccChild):
  745. else
  746. Acc_Role(Acc, child)=Role?Children.Insert(child):
  747. }
  748. return Children.MaxIndex()?Children:, ErrorLevel:=0
  749. } else
  750. ErrorLevel := "AccessibleChildren DllCall Failed"
  751. }
  752. if Acc_Error()
  753. throw Exception(ErrorLevel,-1)
  754. }
  755. Acc_Get(Cmd, ChildPath="", ChildID=0, WinTitle="", WinText="", ExcludeTitle="", ExcludeText="") {
  756. static properties := {Action:"DefaultAction", DoAction:"DoDefaultAction", Keyboard:"KeyboardShortcut"}
  757. AccObj := IsObject(WinTitle)? WinTitle
  758. : Acc_ObjectFromWindow( WinExist(WinTitle, WinText, ExcludeTitle, ExcludeText), 0 )
  759. if ComObjType(AccObj, "Name") != "IAccessible"
  760. ErrorLevel := "Could not access an IAccessible Object"
  761. else {
  762. StringReplace, ChildPath, ChildPath, _, %A_Space%, All
  763. AccError:=Acc_Error(), Acc_Error(true)
  764. Loop Parse, ChildPath, ., %A_Space%
  765. try {
  766. if A_LoopField is digit
  767. Children:=Acc_Children(AccObj), m2:=A_LoopField ; mimic "m2" output in else-statement
  768. else
  769. RegExMatch(A_LoopField, "(\D*)(\d*)", m), Children:=Acc_ChildrenByRole(AccObj, m1), m2:=(m2?m2:1)
  770. if Not Children.HasKey(m2)
  771. throw
  772. AccObj := Children[m2]
  773. } catch {
  774. ErrorLevel:="Cannot access ChildPath Item #" A_Index " -> " A_LoopField, Acc_Error(AccError)
  775. if Acc_Error()
  776. throw Exception("Cannot access ChildPath Item", -1, "Item #" A_Index " -> " A_LoopField)
  777. return
  778. }
  779. Acc_Error(AccError)
  780. StringReplace, Cmd, Cmd, %A_Space%, , All
  781. properties.HasKey(Cmd)? Cmd:=properties[Cmd]:
  782. try {
  783. if (Cmd = "Location")
  784. AccObj.accLocation(ComObj(0x4003,&x:=0), ComObj(0x4003,&y:=0), ComObj(0x4003,&w:=0), ComObj(0x4003,&h:=0), ChildId)
  785. , ret_val := "x" NumGet(x,0,"int") " y" NumGet(y,0,"int") " w" NumGet(w,0,"int") " h" NumGet(h,0,"int")
  786. else if (Cmd = "Object")
  787. ret_val := AccObj
  788. else if Cmd in Role,State
  789. ret_val := Acc_%Cmd%(AccObj, ChildID+0)
  790. else if Cmd in ChildCount,Selection,Focus
  791. ret_val := AccObj["acc" Cmd]
  792. else
  793. ret_val := AccObj["acc" Cmd](ChildID+0)
  794. } catch {
  795. ErrorLevel := """" Cmd """ Cmd Not Implemented"
  796. if Acc_Error()
  797. throw Exception("Cmd Not Implemented", -1, Cmd)
  798. return
  799. }
  800. return ret_val, ErrorLevel:=0
  801. }
  802. if Acc_Error()
  803. throw Exception(ErrorLevel,-1)
  804. }
  805. acc_childrenByName(oAccessible, name,returnOne=false){
  806. items:=Acc_Children(oAccessible)
  807. results := []
  808. for k,item in items
  809. {
  810. if item.accName = name {
  811. if returnOne {
  812. return item
  813. }
  814. results.push(item)
  815. }
  816. }
  817. return results
  818. }
  819. acc_childrenFilter(oAcc, fCondition, value=0, returnOne=false, obj=0){
  820. items:=Acc_Children(oAcc)
  821. results := []
  822. if !IsFunc(fCondition)
  823. return 0
  824. if obj =0
  825. obj:=ACC_FILTERS
  826. methodCallConvention = instr(fCondition.name, ".") > 0
  827. for k,item in items
  828. {
  829. ;fCondition(this ==> stores variables && other methods of object,item,value)
  830. if methodCallConvention {
  831. condition := fCondition.call(obj,item,value)
  832. } else {
  833. condition := fCondition.call(item,value)
  834. }
  835. if condition {
  836. if returnOne {
  837. return item
  838. }
  839. results.push(item)
  840. }
  841. }
  842. return results
  843. }
  844. acc_getRootElement(){
  845. return acc_ObjectFromWindow(0x10010) ;Root object window handle always appears to be 0x10010
  846. }
  847. class ACC_ChildProxy {
  848. __New(oAccParent,id){
  849. global ACC_STATE
  850. this.__accParent := oAccParent
  851. this.__accChildID := id
  852. this.accParent := oAccParent
  853. try {
  854. this.accDefaultAction := oAccParent.accDefaultAction(id)
  855. } catch e {
  856. this.accDefaultAction:=""
  857. }
  858. try {
  859. this.accDescription := oAccParent.accDescription(id)
  860. } catch e {
  861. this.accDescription:=""
  862. }
  863. try {
  864. this.accHelp := oAccParent.accHelp(id)
  865. } catch e {
  866. this.accHelp:=""
  867. }
  868. try {
  869. this.accHelpTopic := oAccParent.accHelpTopic(id)
  870. } catch e {
  871. this.accHelpTopic:=""
  872. }
  873. try {
  874. this.accKeyboardShortcut := oAccParent.accKeyboardShortcut(id)
  875. } catch e {
  876. this.accKeyboardShortcut:=""
  877. }
  878. try {
  879. this.accName := oAccParent.accName(id)
  880. } catch e {
  881. this.accName:=""
  882. }
  883. try {
  884. this.accRole := oAccParent.accRole(id)
  885. } catch e {
  886. this.accRole:=""
  887. }
  888. try {
  889. this.accState := oAccParent.accState(id)
  890. } catch e {
  891. this.accState:=""
  892. }
  893. try {
  894. this.accValue := oAccParent.accValue(id)
  895. } catch e {
  896. this.accValue:=""
  897. }
  898. try {
  899. this.accFocus := this.accState && ACC_STATE.FOCUSED
  900. } catch e {
  901. this.accFocus:=""
  902. }
  903. }
  904. accDoDefaultAction(){
  905. return this.__accParent.accDoDefaultAction(this.__accChildID)
  906. }
  907. accHitTest(){
  908. return false
  909. }
  910. accLocation(ByRef left, Byref top, ByRef width, ByRef height){
  911. return this.__accParent.accLocation(left, top, width, height, this.__accChildID)
  912. }
  913. accNavigate(){
  914. return this.__accParent.accNavigate(navDir,this.__accChildID)
  915. }
  916. accSelect(flagsSelect){
  917. return this.__accParent.accSelect(flagsSelect,this.__accChildID)
  918. }
  919. }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
其他

Acc后台取微信来新消息更新提醒

2021-12-11 14:28:31

其他

修改注册表把cspslock换成Ralt

2021-12-12 21:00:49

5 条回复 A文章作者 M管理员
欢迎您,新朋友,感谢参与互动!
  1. 月下马

    留个脚印,晚些再回来好好看看,研究研究

  2. maxs

    天书级别啊

  3. hexuren
    1河许人给您打赏了¥5
  4. 蜜獾哥
    HoneyBadger给您打赏了¥10
  5. gdzrh917

    mark一下 难得的Acc库相关资料

个人中心
购物车
优惠劵
私信列表
搜索