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

Reply via email to