title: Python for Autohotkey style key-combination sniffing, automation?
body: <p>I want to automate several tasks (eg. simulate eclipse style <kbd>ctrl</kbd>-<kbd>shift</kbd>-<kbd>R</kbd> open dialog for other editors). The general pattern is: the user will press some key combination, my program will detect it and potentially pop up a dialog to get user input, and then run a corresponding command, typically by running an executable.</p>
  
  <p>My target environment is windows, although cross-platform would be nice. My program would be started once, read a configuration file, and sit in the background till triggered by a key combination or other event.</p>
  
  <p>Basically autohotkey.</p>
  
  <p>Why not just use autohotkey? I actually have quite a few autohotkey macros, but I'd prefer to use a saner language.</p>
  
  <p>My question is: is there a good way to have a background python process detect key combinations?</p>
  
  <p>Update: found the answer using pyHook and the win32 extensions:</p>
  
  <pre><code>import pyHook
  import pythoncom
  
  def OnKeyboardEvent(event):
      print event.Ascii
  
  hm = pyHook.HookManager()
  hm.KeyDown = OnKeyboardEvent
  hm.HookKeyboard()
  
  while True:
      pythoncom.PumpMessages()
  </code></pre>