Hi Tim, Thanks for the great explanations.
Yes, you are right, I am trying to intercept gestures in a window within the same process. The Blender application framework has a WndProc in C, and Blender supports extending itself with user-supplied Python scripts. I am trying to add gesture support with Python so I can avoid modifying the Blender C code. I'm reading through the wxPython article. It looks like a perfect fit for my problem. It shows everything I need to do, and using ctypes! Thanks! Although, I am stuck trying to get the HWND from Blender. It seems they have not exposed the handle yet. I'm looking for win32 API that might provide it to me, or a list of windows associated with the process. I guess I have to remove my callback as soon as the WM_DESTROY message is emitted, and reinstantiate the oldWndProc. That makes sense. I'm glad that is shown in the article. I just browsed the Blender C source code and they also use "SetWindowLongPtr" for GWLP_USERDATA, but not for GWLP_WNDPROC. I think everything will work out fine when I find the HWND. Thanks for the expert help. John On Thu, May 9, 2013 at 9:46 AM, Tim Roberts <t...@probo.com> wrote: > John Grant wrote: > > > > I would like to obtain multi-touch events in my Python code (running > > inside Blender's python environment). I have looked around the web for > > a python module that works with py 3.3 (others work with py 2.x), but > > I have not found one. So, I'm trying to build one. > > > > I believe I can use the 'ctypes' to call the function I need, > > GetGestureInfo. > > That gets you gestures, but not multitouch. If all you need is the > zoom, pan and rotate gestures and a two-finger tap, this will do it. > For more complicated gestures, most solutions are custom right now. > > > > This function requires 2 parameters as input, the lParam from WndProc > > and a pointer to the GESTUREINFO structure. > > > > * I hope I can use 'ctypes' to declare the GESTUREINFO structure in my > > python code.* > > I see it is possible to pass structures as pointers using ctypes as well. > > The structure doesn't have any pointers, so this should be straightforward. > > > > *** The problem seems to be obtaining the lParam from WndProc. *** > > > > My idea is to provide a callback function (again using ctypes to > > declare this callback) and use the SetWindowsHookEx function, passing > > my callback and the WH_CALLWNDPROC hook ID. > > > > Does this sound like it will work? > > No, a Windows hook is the wrong answer. That lets you intercept > messages from other processes (which is why hooks need to be in a DLL -- > the DLL actually gets copied and injected into the processes being > hooked). In your case, I assume you're trying to intercept gestures in > a window within your own process. Is that right? As long as you have > the window handle, all you need to do is subclass the window. That > means you make yourself the wndproc for that window, so you get first > shot at all the messages. > > Here's an example that shows how to do this in wxPython, but you can > eliminate the wxPython part of it. The key point is using > win32gui.SetWindowLong to load your own function in > win32con.GWL_WNDPROC, and remembering the return value so you can call > the original function. > http://wiki.wxpython.org/HookingTheWndProc > > -- > Tim Roberts, t...@probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 >
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32