Reputation: 85
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!
Upvotes: 2
Views: 979
Reputation: 77514
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()
Upvotes: 3