views:

207

answers:

3

Has anyone got a working code example of how to connect to the windows message queue(post/sendMessage) and log all messages there? Preferably in Python. I'm interrested in this to easier be able to create test-scripts that emulates user input.

A: 

Usually this is done with SetWindowsHookEx Function.

In Python you probably must use 3rd party libraries, like Python for Windows extensions. PyCWnd.HookMessage and PyCWnd.HookAllKeyStrokes might be what you need.

Nick D
A: 

There's actually a package that wraps the SetWindowsHookEx function, called pyHook. I've used it before to write a primitive key-logger (as an experiment in monitoring myself to assist with reporting work hours) and it worked fine for that.

Peter Hansen
A: 

You can use SetWinEventHook to catch most system windowing activity. The advantage from traditional hooks is that you can do it from your process, that is, you don't need to write a hooking DLL. Also, when the thread that called SetWinEventHook finishes, Windows releases the handler automatically. Having out of context hooking prevents you from crashing other applications, as a minimal error on an injected DLL will possibly do.

Hernán