title: Python ctypes: SetWindowsHookEx callback function never called
body: <p>I'm trying to write a program in Python that is aware of when alert boxes/dialogues are shown. It's dealing with multiple monitors, and I want it to display a visualization on the secondary monitor when a taskbar icon flashes, an error/notification pops up, etc.</p>
  
  <p>As far as I can tell, the way to do detect these events is using message hooks, as described here: <a href="http://msdn.microsoft.com/en-us/library/ms632589%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms632589%28v=vs.85%29.aspx</a></p>
  
  <p>I was even lucky enough to find an example that accesses the SetWindowsHookEx function from Python. (This particular example uses mouse signals, but I can just change the constants to listen for different messages).
  <a href="http://www.python-forum.org/pythonforum/viewtopic.php?f=2&amp;t=11154" rel="nofollow">http://www.python-forum.org/pythonforum/viewtopic.php?f=2&amp;t=11154</a></p>
  
  <p>However, the above example does not work. The callback function is never called, regardless of my mouse clicks, and a middle mouse click does not cause the program to exit.</p>
  
  <p>The example is from 2009 (pre windows 7?),though I don't know if that's the issue.</p>
  
  <p>So, my question is, can anybody 1. find out why the code works, or 2. tell me another way to achieve what I'm doing (preferably in Python, though I'll go to other languages if necesarry).</p>
  
  <p><strong>Edit:</strong> Is it possible to do what I'm wanting with WMI? I don't know WMI well, but I know that it does have very good Python interface.</p>