<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>> From: shanesclark@hotmail.com<br>> To: gagsl-py2@yahoo.com.ar; python-list@python.org<br>> Subject: RE: Getting name of control under mouse in Windows?<br>> Date: Mon, 19 Nov 2007 17:16:13 -0500<br>> <br>> <br>> ----------------------------------------<br>> > To: python-list@python.org<br>> > From: gagsl-py2@yahoo.com.ar<br>> > Subject: Re: Getting name of control under mouse in Windows?<br>> > Date: Mon, 19 Nov 2007 03:33:24 -0300<br>> > <br>> > En Sun, 18 Nov 2007 21:10:18 -0300, Shane Clark   <br>> > escribió:<br>> > <br>> >>> From: gagsl-py2@yahoo.com.ar<br>> >>><br>> >>> En Fri, 16 Nov 2007 16:16:25 -0300, Shane Clark<br>> >>> escribió:<br>> >>><br>> >>>> I am trying to get my python app to output the name of the control  <br>> >>>> under<br>> >>>> the mouse each time it is clicked. Currently, I am trying to do this<br>> >>>> with a combination of pyhook and pyAA, but pyAA gives me "pyAA.Error:<br>> >>>> -2147417843" for almost any control in Microsoft Office apps, for<br>> >>>> example. If it matters, I am trying to retrieve the control's name  <br>> >>>> based<br>> >>>> on the mouse position coordinates.<br>> >>><br>> >>> pywinauto does that.<br>> >>><br>> >> Thanks for the response. Pywinauto is more or less incompatible with  <br>> >> Office apps so far as I can tell. According to what I have read, this is  <br>> >> because Office does not use standard Windows controls. For more info:  <br>> >> http://forums.openqa.org/message.jspa?messageID=28199<br>> > <br>> > Ouch. In that case I think you won't gain much by knowing the control name  <br>> > anyway...<br>> > <br>> > -- <br>> > Gabriel Genellina<br>> > <br>> > -- <br>> > http://mail.python.org/mailman/listinfo/python-list<br>> <br>> Actually, the name of the control is all that I am after. I am working on a forensics toolkit for a professor of mine and I just want to know the name of the button that was clicked. Anyone have other suggestions?<br>> <br>> Shane Clark<br>> _________________________________________________________________<br>> Your smile counts. The more smiles you share, the more we donate.  Join in.<br>> www.windowslive.com/smile?ocid=TXT_TAGLM_Wave2_oprsmilewlhmtagline<br>> -- <br>> http://mail.python.org/mailman/listinfo/python-list<br><br>I got it working using comtypes. Thank you for the suggestions. Here is my code if anyone else is interested.<br><br><code><br>import pythoncom, pyHook<br>from threading import Timer<br>from ctypes import oledll, windll, byref, POINTER<br>from ctypes.wintypes import POINT<br>from comtypes.client import wrap<br>from comtypes.automation import VARIANT<br>from comtypes import IUnknown<br><br>oleacc = oledll.oleacc<br><br>def AccessibleObjectFromPoint(x, y):<br>   pacc = POINTER(IUnknown)()<br>   var = VARIANT()<br>   oleacc.AccessibleObjectFromPoint(POINT(x, y),<br>                                    byref(pacc),<br>                                    byref(var))<br>   return wrap(pacc), var.value<br><br>def ShowButton():<br>   pythoncom.CoInitialize()<br>   x,y, = GetCursorPos()<br>   pacc, value = AccessibleObjectFromPoint(x, y)<br>   print pacc.accName()<br>   <br>def GetCursorPos():<br>   pt = POINT()<br>   windll.user32.GetCursorPos(byref(pt))<br>   return pt.x, pt.y<br><br>def OnMouseClick(event):<br>   #pythoncom.CoInitialize()<br>   t = Timer(0.01, ShowButton)<br>   t.start()<br>   # return True to pass the event to other handlers<br>   return True<br><br>if __name__ == "__main__":<br>   #pythoncom.CoInitialize()<br>   # create a hook manager<br>   hm = pyHook.HookManager()<br>   # watch for left-click events<br>   hm.MouseLeftDown = OnMouseClick<br>   # set the hook<br>   hm.HookMouse()<br>   # wait forever<br>   pythoncom.PumpMessages()<br></code><br><br>-Shane Clark<br><br /><hr />Your smile counts. The more smiles you share, the more we donate. <a href='www.windowslive.com/smile?ocid=TXT_TAGLM_Wave2_oprsmilewlhmtagline' target='_new'>Join in!</a></body>
</html>