Thanks for the help. I will have to checkout PyAA from CVS and see how
far I get.

Shane

On Tue, Feb 26, 2008 at 11:00 AM, MR Michael Robellard (5314)
<[EMAIL PROTECTED]> wrote:
> The short answer is use pyAA.
>
> I tried your script on my machine and also saw the same bug.
> I switched your code around to use pyAA instead and everything worked as
> expected.
> Here is your changed code.
> I also imported win32traceutil to output the clicks to the Python Trace
> Collector
>
> This isn't really an answer, just a work around
>
> import pythoncom, pyHook
> from threading import Timer
> 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
> import win32traceutil
> import pyAA
>
> oleacc = oledll.oleacc
>
> def AccessibleObjectFromPoint(x, y):
>   #pacc = POINTER(IUnknown)()
>   var = VARIANT()
>   pacc = pyAA.AccessibleObjectFromPoint((x, y))
>   return pacc, var.value
>
> def ShowButton():
>   pythoncom.CoInitialize()
>   x,y, = GetCursorPos()
>   pacc, value = AccessibleObjectFromPoint(x, y)
>   print pacc
>   print pacc.Name()
>
> def GetCursorPos():
>   pt = POINT()
>   windll.user32.GetCursorPos(byref(pt))
>   return pt.x, pt.y
>
> # Event handler
> def OnMouseClick(event):
>   t = Timer(0.01, ShowButton)
>   t.start()
>   return True
>
> if __name__ == "__main__":
>   hm = pyHook.HookManager()
>   hm.MouseLeftDown = OnMouseClick
>   hm.HookMouse()
>   pythoncom.PumpMessages()
>
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Shane
> Clark
> Sent: Tuesday, February 26, 2008 9:37 AM
> To: comtypes-users@lists.sourceforge.net
> Subject: [comtypes-users] Confusion with accessible objects
>
> Hi,
>
> I am trying to do some Windows automation and I am having alot of
> trouble with even finding the names of the controls that I would like to
> manipulate. I need to launch a media player and play a file, so I wrote
> a quick little script to just grab the name of the control under my
> mouse when I click. It fails miserably in many programs with the
> following error:
>
> Exception in thread Thread-5:
> Traceback (most recent call last):
>  File "C:\Python25\lib\threading.py", line 460, in __bootstrap
>    self.run()
>  File "C:\Python25\lib\threading.py", line 625, in run
>    self.function(*self.args, **self.kwargs)
>  File "comhook.py", line 23, in ShowButton
>    print pacc.accName()
>  File "C:\Python25\Lib\site-packages\comtypes\__init__.py", line 607,
> in __call __
>    return self.getter(self.im_inst, *args)
> COMError: (-2147024809, 'The parameter is incorrect.', (None, None,
> None, 0, Non
> e))
>
> Am I completely misunderstanding something or going about this the wrong
> way?
> Here is my code for reference:
>
> import pythoncom, pyHook
> from threading import Timer
> 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 ShowButton():
>   pythoncom.CoInitialize()
>   x,y, = GetCursorPos()
>   pacc, value = AccessibleObjectFromPoint(x, y)
>   print pacc.accName()
>
> def GetCursorPos():
>   pt = POINT()
>   windll.user32.GetCursorPos(byref(pt))
>   return pt.x, pt.y
>
> # Event handler
> def OnMouseClick(event):
>   t = Timer(0.01, ShowButton)
>   t.start()
>   return True
>
> if __name__ == "__main__":
>   hm = pyHook.HookManager()
>   hm.MouseLeftDown = OnMouseClick
>   hm.HookMouse()
>   pythoncom.PumpMessages()
>
> Any help is appreciated.
>
> ------------------------------------------------------------------------
>
> -
> This SF.net email is sponsored by: Microsoft Defy all challenges.
> Microsoft(R) Visual Studio 2008.
> 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
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> 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
>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
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

Reply via email to