Shane Clark schrieb: > Hi, > > I am trying to get my python app to output the name of the control > under the mouse each time it is clicked. Currently, I am trying to do > this with a combination of pyhook and pyAA, but pyAA gives me errors > for almost any control in Microsoft Office and some other apps that I > need to support. > > I have seen comtypes referenced several times while searching for > answers, but I am intermediate at best in Python and do not have great > knowledge of COM in general. Could anyone point me in the right > direction on how I might get this functionality using comtypes?
I have no idea what the problems with pyhook or pyAA are, but I made a simple script for comtypes that works for me, with comtypes 0.4.0. When I have MS Word open, and the cursor is over the 'Save' button, the document is saved when I run the script. It may get you started. Thomas <code> from ctypes import oledll, windll, byref, POINTER from ctypes.wintypes import POINT from comtypes.client import wrap from comtypes.automation import VARIANT from comtypes import IUnknown oleacc = oledll.oleacc def AccessibleObjectFromPoint(x, y): pacc = POINTER(IUnknown)() var = VARIANT() oleacc.AccessibleObjectFromPoint(POINT(x, y), byref(pacc), byref(var)) return wrap(pacc), var.value def GetCursorPos(): pt = POINT() windll.user32.GetCursorPos(byref(pt)) return pt.x, pt.y if __name__ == "__main__": x, y = GetCursorPos() pacc, value = AccessibleObjectFromPoint(x, y) print pacc.accName() print pacc.accDefaultAction() print pacc.accDoDefaultAction() <code/> ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users