title: how to remap a keystroke in Python
body: <p>How could a keystroke (for example, the tab key) be remapped to produce something such as an "a" or multiple keystrokes such as four spaces? I am writing an editor in Python (using PyQt4) and would like to allow the user to control what various keystrokes do. An example would be to control whether the tab key produces a tab or a number of spaces in the editor. I would like this behaviour to be isolated to the editor and to avoid dependencies on programs such as <code>xmodmap</code>.</p>
  
  <p>While the editor is likely to be run only on Linux, it would be interesting to know how this behaviour could be made portable and I am interested also in security suggestions for something like this.</p>
  
  <p>Thanks!</p>