Q:

How do you map a keyboard key in Python 2.7?

I was wondering how do you map a key in python 2.7 to do something, like if you pressed 'a' (without having to hit enter), you would get a print statement.
Thanks a bunch in advance!

A:

You could use Tkinter or PyQT or some other library that offers event handling. For example:
import Tkinter as tk

def key_press(event):
    print event.char
    return event.char
    # Or whatever processing you might want.

tk_app = tk.Tk()
tk_app.bind('<KeyPress>', key_press)
tk_app.mainloop()

