autoHotkey进阶 — 用于访问窗口对象-acc库的简单配置
引言
accessible( acc) 库,是ahk的一个第三方的代码库.这个库通过访问微软库的底层api函数(Microsoft Active Accessibility (MSAA))实现一些窗口的基础操作函数.从名字也可以看出来,主要是让我们访问窗口的一些对象. 例如用于监测窗口\控件\gui元素的信息. 根据这些信息做一些特殊操作,或者操作这些对象的状态. 例如检测按钮的位置,并设置自动单击.
Microsoft Active Accessibility (MSAA) 是用于用户界面可访问性的应用程序编程接口 (API)。MSAA于1997年作为Microsoft Windows 95的平台附加组件引入。MSAA 旨在帮助辅助技术 (AT) 产品与应用程序(或操作系统)的标准和自定义用户界面 (UI) 元素进行交互,以及访问、识别和操作应用程序的 UI 元素。AT 产品与支持 MSAA 的应用程序配合使用,以便为有身体或认知困难、障碍或残疾的个人提供更好的访问。AT 产品的一些示例包括:用于视力受限用户的屏幕阅读器、适用于物理访问受限用户的屏幕键盘或用于听力受限用户的讲述人。MSAA还可用于自动化测试工具和基于计算机的培训应用程序。—引自维基百科
参考博客列表
配置过程
- 下载github的代码 accV2下载地址
- 解压缩得到下面的
- 将AccV2.ahk 复制到和自己的脚本同个文件夹下.
也有介绍说把这个库直接放在ahk软件的库里面的. 我暂时没有采用这种方法.
5. 在自己脚本的开头引入上面的脚本,这样就可以用acc的函数了. 函数介绍看下面,或者打开 accV2.ahk脚本,在开头有英文介绍.
资源
-
jeeswg教程(英文)
这个下面有很多这个作者的案例脚本,自己可以查阅
函数列表
;----------------------------------------------------------------------------------------------------------------------
; Acc.ahk
;----------------------------------------------------------------------------------------------------------------------
; Authors (dd/mm/yyyy):
; Sean ()
; jethrow (19/02/2012)
; Sancarn (26/11/2017,18/01/2019,10/05/2019)
;----------------------------------------------------------------------------------------------------------------------
; CHANGE LOG:
;----------------------------------------------------------------------------------------------------------------------
;19/02/2012:
; Modified ComObjEnwrap params from (9,pacc) --> (9,pacc,1)
; Changed ComObjUnwrap to ComObjValue in order to avoid AddRef (thanks fincs)
; Added Acc_GetRoleText & Acc_GetStateText
; Added additional functions - commented below
; Removed original Acc_Children function
;26/11/2017:
; Added Enumerations as Objects
; Added IAccessible walking functionality e.g.
; acc_childrenFilter(oAcc, ACC_FILTERS.byDescription, "Amazing button")
;
; acc_childrenFilter(oAcc, Func("myAwesomeFunction"), true)
; myAwesomeFunction(oAcc,val){
; return val
; }
; Added Acc_ChildProxy to Acc_Children
;18/01/2019:
; Documentation Update
;10/05/2019:
; Error Checking to ACC_ChildProxy
;----------------------------------------------------------------------------------------------------------------------
;ACC INTELLISENSE PACK:
;----------------------------------------------------------------------------------------------------------------------
;IAcc Member Properties: [accChild,accChildCount,accDefaultAction,accDescription,accFocus,accHelp,accHelpTopic,accKeyboardShortcut,accName,accParent,accRole,accSelection,accState,accValue]
;Member Methods: [accDoDefaultAction,accHitTest,accLocation,accNavigate,accSelect]
;Global Constants: [ACC_NAVDIR,ACC_SELECTIONFLAG,ACC_EVENT,VT_CONSTANTS,ACC_FILTERS,ACC_OBJID,ACC_STATE,ACC_ROLE]
;Global Methods: [Acc_ObjectFromEvent,Acc_ObjectFromPoint,Acc_ObjectFromWindow,Acc_WindowFromObject,Acc_SetWinEventHook,Acc_UnhookWinEvent,Acc_Location,Acc_Parent,Acc_Child,Acc_Children,Acc_Get,acc_childrenFilter,acc_getRootElement]
;
;----------------------------------------------------------------------------------------------------------------------
; DOCUMENTATION:
;----------------------------------------------------------------------------------------------------------------------
;IAcc Member Properties:
; accChild Read-only An IDispatch interface for the specified child, if one exists. All objects must support this property. See get_accChild.
; accChildCount Read-only The number of children that belong to this object. All objects must support this property. See get_accChildCount.
; accDefaultAction Read-only A string that describes the object's default action. Not all objects have a default action. See get_accDefaultAction.
; accDescription Read-only Note The accDescription property is not supported in the transition to UI Automation. Microsoft Active Accessibility servers and applications should not use it. A string that describes the visual appearance of the specified object. Not all objects have a description.
; accFocus Read-only The object that has the keyboard focus. All objects that receive the keyboard focus must support this property. See get_accFocus.
; accHelp Read-only A help string. Not all objects support this property. See get_accHelp.
; accHelpTopic Read-only Note The accHelpTopic property is deprecated and should not be used.The full path of the help file associated with the specified object and the identifier of the appropriate topic within that file. Not all objects support this property.
; accKeyboardShortcut Read-only The object's shortcut key or access key, also known as the mnemonic. All objects that have a shortcut key or an access key support this property. See get_accKeyboardShortcut.
; accName Read-only The name of the object. All objects support this property. See get_accName.
; accParent Read-only The IDispatch interface of the object's parent. All objects support this property. See get_accParent.
; accRole Read-only Information that describes the role of the specified object. All objects support this property. See get_accRole.
; accSelection Read-only The selected children of this object. All objects that support selection must support this property. See get_accSelection.
; accState Read-only The current state of the object. All objects support this property. See get_accState.
; accValue Read/write The value of the object. Not all objects have a value. See get_accValue, put_accValue.
;Member Methods:
; accDoDefaultAction Performs the specified object's default action. Not all objects have a default action.
; accHitTest Retrieves the child element or child object at a given point on the screen. All visual objects support this method.
; accLocation Retrieves the specified object's current screen location. All visual objects support this method.
; accNavigate Note The accNavigate method is deprecated and should not be used. Clients should use other methods and properties such as AccessibleChildren, get_accChild, get_accParent, and IEnumVARIANT. Traverses to another user interface element within a container and retrieves the object. All visual objects support this method.
; accSelect Modifies the selection or moves the keyboard focus of the specified object. All objects that support selection or receive the keyboard focus must support this method.
;Global Constants:
; ACC_NAVDIR Object containing different navigation direction flags.
; ACC_SELECTIONFLAG Object containing different accSelect() Flags.
; ACC_EVENT Object containing different windows events which can be used with Acc_ObjectFromEvent.
; VT_CONSTANTS Object containing different COM VTable constants.
; ACC_FILTERS Object containing filter functions to be used with acc_childrenFilter.
; ACC_OBJID Object containing different object names and ids.
; ACC_STATE Object containing different state names and ids.
; ACC_ROLE Object containing different role names and ids.
;Global Methods:
; Acc_ObjectFromEvent(ByRef _idChild_, hWnd, idObject, idChild) - Used to get Acc object from Event
; Acc_ObjectFromPoint(ByRef _idChild_ = "", x = "", y = "") - Used to get Acc object from X,Y Point
; Acc_ObjectFromWindow(hWnd, idObject = -4) - Used to get Acc object from hWND
; Acc_WindowFromObject(pacc) - Used to get hWND from ACC object
; Acc_SetWinEventHook(eventMin, eventMax, pCallback) - Listen for Windows events. Call callback with Acc object param.
; Acc_UnhookWinEvent(hHook) - Stop listening to existing event hook.
; Acc_Location(Acc, ChildId=0) - Get the location of an IAccessible object
; Acc_Parent(Acc) - Get the parent object of an element
; Acc_Child(Acc, ChildId=0) - Get a child of the object with a specified id.
; Acc_Children(Acc) - Get the children of an IAccessible object (as an array)
; Acc_Get(Cmd, ChildPath="", ChildID=0, WinTitle="", WinText="", ExcludeTitle="", ExcludeText="") - Get an accessible object
; acc_childrenFilter(oAcc, fCondition, value=0, returnOne=false, obj=0) - Filter children by some defined condition
; acc_getRootElement() - Returns the Acc Object for the Desktop (Root of all Acc tree elements)
;DEPRECATED AND INTERNAL METHODS:
; Acc_Init() - DO NOT CALL!
; Acc_Query(Acc) - DO NOT CALL! Query IAccessible interface from object
; Acc_Error(p="") - DO NOT CALL! Error information
; Acc_GetRoleText(nRole) - [DEPRECATED. USE ACC_ROLE OBJECT ] Get's ACC Role as Text.
; Acc_GetStateText(nState) - [DEPRECATED. USE ACC_STATE OBJECT ] Get's ACC State as Text.
; Acc_Role(Acc, ChildId=0) - [DEPRECATED. USE ACC_ROLE OBJECT ]
; Acc_State(Acc, ChildId=0) - [DEPRECATED. USE ACC_STATE OBJECT ]
; Acc_ChildrenByRole(Acc, Role) - [DEPRECATED. USE acc_childrenFilter] Get all children of the specified role.
; acc_childrenByName(oAccessible, name,returnOne=false) - [DEPRECATED. USE acc_childrenFilter]Filter children by name, if returnOne then only 1 child is returned
;
;----------------------------------------------------------------------------------------------------------------------
;Further descriptions:
;----------------------------------------------------------------------------------------------------------------------
;acc_childrenFilter
; Filters the children in an acc object and calls the function defined by the 2nd parameter with Acc object and the 3rd param.
; If the function returns true, the child is included in the filter.
;Example:
; The following function will include children based on the 3rd parameter:
; acc_childrenFilter(oAcc, Func("myAwesomeFunction"), true) ;Returns all children
; acc_childrenFilter(oAcc, Func("myAwesomeFunction"), true) ;Returns no children
; myAwesomeFunction(oAcc,val){
; return val
; }
;
;ACC_FILTERS
; These are commonly used in conjunction with `acc_childrenFilter`:
;Example:
; acc_childrenFilter(oAcc, ACC_FILTERS.byDescription, "Amazing button")
;List of helper methods:
; ACC_FILTERS.byDefaultAction(oAcc,action) - Filter children by a specific default action
; ACC_FILTERS.byDescription(oAcc,desc) - Filter children by a specific description
; ACC_FILTERS.byValue(oAcc, value) - Filter children by a specific value
; ACC_FILTERS.byHelp(oAcc, hlpTxt) - Filter children by a specific help text
; ACC_FILTERS.byState(oAcc, state) - Filter children by a specific state
; ACC_FILTERS.byRole(oAcc, role) - Filter children by a specific role
; ACC_FILTERS.byName(oAcc, name) - Filter children by a specific name
; ACC_FILTERS.byRegex(oAcc, regex) - Filter children by regex matching against string: %accName%;%accHelp%;%accValue%;%accDescription%;%accDefaultAction%
;----------------------------------------------------------------------------------------------------------------------