3 from ctypes.wintypes import *
\r
4 from comtypes import *
\r
5 from comtypes.automation import *
\r
6 import comtypes.client
\r
9 # Include functions from oleacc.dll in the module namespace.
\r
10 m=comtypes.client.GetModule('oleacc.dll')
\r
11 globals().update((key, val) for key, val in m.__dict__.iteritems() if not key.startswith("_"))
\r
24 ROLE_SYSTEM_TITLEBAR=1
\r
25 ROLE_SYSTEM_MENUBAR=2
\r
26 ROLE_SYSTEM_SCROLLBAR=3
\r
29 ROLE_SYSTEM_CURSOR=6
\r
32 ROLE_SYSTEM_WINDOW=9
\r
33 ROLE_SYSTEM_CLIENT=10
\r
34 ROLE_SYSTEM_MENUPOPUP=11
\r
35 ROLE_SYSTEM_MENUITEM=12
\r
36 ROLE_SYSTEM_TOOLTIP=13
\r
37 ROLE_SYSTEM_APPLICATION=14
\r
38 ROLE_SYSTEM_DOCUMENT=15
\r
40 ROLE_SYSTEM_CHART=17
\r
41 ROLE_SYSTEM_DIALOG=18
\r
42 ROLE_SYSTEM_BORDER=19
\r
43 ROLE_SYSTEM_GROUPING=20
\r
44 ROLE_SYSTEM_SEPARATOR=21
\r
45 ROLE_SYSTEM_TOOLBAR=22
\r
46 ROLE_SYSTEM_STATUSBAR=23
\r
47 ROLE_SYSTEM_TABLE=24
\r
48 ROLE_SYSTEM_COLUMNHEADER=25
\r
49 ROLE_SYSTEM_ROWHEADER=26
\r
50 ROLE_SYSTEM_COLUMN=27
\r
54 ROLE_SYSTEM_HELPBALLOON=31
\r
55 ROLE_SYSTEM_CHARACTER=32
\r
57 ROLE_SYSTEM_LISTITEM=34
\r
58 ROLE_SYSTEM_OUTLINE=35
\r
59 ROLE_SYSTEM_OUTLINEITEM=36
\r
60 ROLE_SYSTEM_PAGETAB=37
\r
61 ROLE_SYSTEM_PROPERTYPAGE=38
\r
62 ROLE_SYSTEM_INDICATOR=39
\r
63 ROLE_SYSTEM_GRAPHIC=40
\r
64 ROLE_SYSTEM_STATICTEXT=41
\r
66 ROLE_SYSTEM_PUSHBUTTON=43
\r
67 ROLE_SYSTEM_CHECKBUTTON=44
\r
68 ROLE_SYSTEM_RADIOBUTTON=45
\r
69 ROLE_SYSTEM_COMBOBOX=46
\r
70 ROLE_SYSTEM_DROPLIST=47
\r
71 ROLE_SYSTEM_PROGRESSBAR=48
\r
73 ROLE_SYSTEM_HOTKEYFIELD=50
\r
74 ROLE_SYSTEM_SLIDER=51
\r
75 ROLE_SYSTEM_SPINBUTTON=52
\r
76 ROLE_SYSTEM_DIAGRAM=53
\r
77 ROLE_SYSTEM_ANIMATION=54
\r
78 ROLE_SYSTEM_EQUATION=55
\r
79 ROLE_SYSTEM_BUTTONDROPDOWN=56
\r
80 ROLE_SYSTEM_BUTTONMENU=57
\r
81 ROLE_SYSTEM_BUTTONDROPDOWNGRID=58
\r
82 ROLE_SYSTEM_WHITESPACE=59
\r
83 ROLE_SYSTEM_PAGETABLIST=60
\r
84 ROLE_SYSTEM_CLOCK=61
\r
85 ROLE_SYSTEM_SPLITBUTTON=62
\r
86 ROLE_SYSTEM_IPADDRESS=63
\r
87 ROLE_SYSTEM_OUTLINEBUTTON=64
\r
89 STATE_SYSTEM_NORMAL=0
\r
90 STATE_SYSTEM_UNAVAILABLE=0x1
\r
91 STATE_SYSTEM_SELECTED=0x2
\r
92 STATE_SYSTEM_FOCUSED=0x4
\r
93 STATE_SYSTEM_PRESSED=0x8
\r
94 STATE_SYSTEM_CHECKED=0x10
\r
95 STATE_SYSTEM_MIXED=0x20
\r
96 STATE_SYSTEM_INDETERMINATE=STATE_SYSTEM_MIXED
\r
97 STATE_SYSTEM_READONLY=0x40
\r
98 STATE_SYSTEM_HOTTRACKED=0x80
\r
99 STATE_SYSTEM_DEFAULT=0x100
\r
100 STATE_SYSTEM_EXPANDED=0x200
\r
101 STATE_SYSTEM_COLLAPSED=0x400
\r
102 STATE_SYSTEM_BUSY=0x800
\r
103 STATE_SYSTEM_FLOATING=0x1000
\r
104 STATE_SYSTEM_MARQUEED=0x2000
\r
105 STATE_SYSTEM_ANIMATED=0x4000
\r
106 STATE_SYSTEM_INVISIBLE=0x8000
\r
107 STATE_SYSTEM_OFFSCREEN=0x10000
\r
108 STATE_SYSTEM_SIZEABLE=0x20000
\r
109 STATE_SYSTEM_MOVEABLE=0x40000
\r
110 STATE_SYSTEM_SELFVOICING=0x80000
\r
111 STATE_SYSTEM_FOCUSABLE=0x100000
\r
112 STATE_SYSTEM_SELECTABLE=0x200000
\r
113 STATE_SYSTEM_LINKED=0x400000
\r
114 STATE_SYSTEM_TRAVERSED=0x800000
\r
115 STATE_SYSTEM_MULTISELECTABLE=0x1000000
\r
116 STATE_SYSTEM_EXTSELECTABLE=0x2000000
\r
117 STATE_SYSTEM_ALERT_LOW=0x4000000
\r
118 STATE_SYSTEM_ALERT_MEDIUM=0x8000000
\r
119 STATE_SYSTEM_ALERT_HIGH=0x10000000
\r
120 STATE_SYSTEM_PROTECTED=0x20000000
\r
121 STATE_SYSTEM_HASPOPUP=0x40000000
\r
122 STATE_SYSTEM_VALID=0x7fffffff
\r
125 SELFLAG_TAKEFOCUS=1
\r
126 SELFLAG_TAKESELECTION=2
\r
127 SELFLAG_EXTENDSELECTION=4
\r
128 SELFLAG_ADDSELECTION=8
\r
129 SELFLAG_REMOVESELECTION=16
\r
132 def LresultFromObject(wParam,obj):
\r
134 returns a reference, similar to a handle, to the specified object.
\r
135 Servers return this reference when handling WM_GETOBJECT.
\r
136 @param wParam: the wParam value passed in with WM_GETOBJECT.
\r
138 @param obj: the COM object instance you want a reference for.
\r
139 @type obj: COMObject
\r
140 @return: a reference to the object.
\r
144 return oledll.oleacc.LresultFromObject(byref(objIID),wParam,obj)
\r
146 def ObjectFromLresult(res,wParam,interface):
\r
148 retrieves a requested interface pointer for an accessible object
\r
149 based on a previously generated object reference.
\r
150 @param res: the previously generated object reference.
\r
152 @param wParam: the wParam value passed in with WM_GETOBJECT.
\r
154 @param interface: the requested COM interface.
\r
155 @type interface: comtypes COM interface
\r
156 @return: the object.
\r
159 p=POINTER(interface)()
\r
160 oledll.oleacc.ObjectFromLresult(res,byref(interface._iid_),wParam,byref(p))
\r
163 def CreateStdAccessibleProxy(hwnd,className,objectID,interface=IAccessible):
\r
165 creates an accessible object using a specific window class, with the methods and properties
\r
166 of the specified type of system-provided user interface element.
\r
167 @param hwnd: the handle of the window this accessible object should represent.
\r
169 @param className: the window class name to use.
\r
170 @type className: basestring
\r
171 @param objectID: an OBJID_* constant or custom value stating the specific object in the window.
\r
172 @type objectID: int
\r
173 @param interface: the requested COM interface for this object. Defaults to IAccessible.
\r
174 @type interface: comtypes COM interface
\r
175 @return: the created object.
\r
178 p=POINTER(interface)()
\r
179 oledll.oleacc.CreateStdAccessibleProxyW(hwnd,className,objectID,byref(interface._iid_),byref(p))
\r
182 def CreateStdAccessibleObject(hwnd,objectID,interface=IAccessible):
\r
184 creates an accessible object with the methods and properties
\r
185 of the specified type of system-provided user interface element.
\r
186 @param hwnd: the handle of the window this accessible object should represent.
\r
188 @param objectID: an OBJID_* constant or custom value stating the specific object in the window.
\r
189 @type objectID: int
\r
190 @param interface: the requested COM interface for this object. Defaults to IAccessible.
\r
191 @type interface: comtypes COM interface
\r
192 @return: the created object.
\r
195 p=POINTER(interface)()
\r
196 oledll.oleacc.CreateStdAccessibleObject(hwnd,objectID,byref(interface._iid_),byref(p))
\r
199 def AccessibleObjectFromWindow(hwnd,objectID,interface=IAccessible):
\r
201 Retreaves a COM object from the given window, with the given object ID.
\r
202 @param hwnd: the handle of the window to retreave the object from.
\r
204 @param objectID: one of the OBJID_* constants or a custom positive value representing the specific object you want to retreave.
\r
205 @type objectID: int
\r
206 @param interface: the requested COM interface you wish to use on the retreaved object.
\r
207 @type interface: comtypes COM interface
\r
208 @return: the retreaved object.
\r
211 p=POINTER(interface)()
\r
212 oledll.oleacc.AccessibleObjectFromWindow(hwnd,objectID,byref(p._iid_),byref(p))
\r
215 def AccessibleObjectFromWindow_safe(hwnd,objectID,interface=IAccessible,timeout=2):
\r
217 raise ValueError("Invalid window")
\r
219 res=windll.user32.SendMessageTimeoutW(hwnd,winUser.WM_GETOBJECT,0,objectID,winUser.SMTO_ABORTIFHUNG,int(timeout*1000),byref(wmResult))==0
\r
221 raise OSError("WM_GETOBJECT failed")
\r
223 return ObjectFromLresult(wmResult.value,0,interface)
\r
224 return CreateStdAccessibleObject(hwnd,objectID,interface)
\r
226 def AccessibleObjectFromEvent(hwnd,objectID,childID):
\r
228 Retreaves an IAccessible object from the given window, with the given object ID and child ID.
\r
229 @param hwnd: the handle of the window to retreave the object from.
\r
231 @param objectID: one of the OBJID_* constants or a custom positive value representing the specific object you want to retreave.
\r
232 @type objectID: int
\r
233 @param childID: the ID of the child element you wish to retreave.
\r
235 @return: the retreaved object.
\r
238 p=POINTER(IAccessible)()
\r
240 oledll.oleacc.AccessibleObjectFromEvent(hwnd,objectID,childID,byref(p),byref(varChild))
\r
241 if varChild.vt==VT_I4:
\r
242 childID=varChild.value
\r
245 def AccessibleObjectFromEvent_safe(hwnd,objectID,childID,timeout=2):
\r
246 obj=AccessibleObjectFromWindow_safe(hwnd,objectID,timeout=timeout)
\r
248 raise RuntimeError("AccessibleObjectFromWindow failed")
\r
251 childObj=obj.accChild(childID)
\r
257 return (obj,childID)
\r
259 def WindowFromAccessibleObject(pacc):
\r
261 Retreaves the handle of the window this IAccessible object belongs to.
\r
262 @param pacc: the IAccessible object who's window you want to fetch.
\r
263 @type pacc: POINTER(IAccessible)
\r
264 @return: the window handle.
\r
268 oledll.oleacc.WindowFromAccessibleObject(pacc,byref(hwnd))
\r
271 def AccessibleObjectFromPoint(x,y):
\r
273 pacc=POINTER(IAccessible)()
\r
275 oledll.oleacc.AccessibleObjectFromPoint(point,byref(pacc),byref(varChild))
\r
276 if not isinstance(varChild.value,int):
\r
279 child=varChild.value
\r
280 return (pacc,child)
\r
282 def AccessibleChildren(pacc,iChildStart,cChildren):
\r
283 varChildren=(VARIANT*cChildren)()
\r
285 oledll.oleacc.AccessibleChildren(pacc,iChildStart,cChildren,byref(varChildren),byref(pcObtained))
\r
286 return [x.value for x in varChildren[0:pcObtained.value]]
\r
288 def GetProcessHandleFromHwnd(windowHandle):
\r
289 """Retreaves a process handle of the process who owns the window.
\r
290 If Windows Vista, uses GetProcessHandleFromHwnd found in oleacc.dll which allows a client with UIAccess to open a process who is elevated.
\r
291 if older than Windows Vista, just uses OpenProcess from user32.dll instead.
\r
292 @param windowHandle: a window of a process you wish to retreave a process handle for
\r
293 @type windowHandle: integer
\r
294 @returns: a process handle with read, write and operation access
\r
298 return oledll.oleacc.GetProcessHandleFromHwnd(windowHandle)
\r
301 return winKernel.openProcess(winKernel.PROCESS_VM_READ|winKernel.PROCESS_VM_WRITE|winKernel.PROCESS_VM_OPERATION,False,winUser.getWindowThreadProcessID(windowHandle)[0])
\r
303 def GetRoleText(role):
\r
304 textLen=oledll.oleacc.GetRoleTextW(role,0,0)
\r
306 buf=create_unicode_buffer(textLen+2)
\r
307 oledll.oleacc.GetRoleTextW(role,buf,textLen+1)
\r
312 def GetStateText(state):
\r
313 textLen=oledll.oleacc.GetStateTextW(state,0,0)
\r
315 buf=create_unicode_buffer(textLen+2)
\r
316 oledll.oleacc.GetStateTextW(state,buf,textLen+1)
\r