When I push the print screen button on my keyboard, I would like to trigger an event, like this:
if keyboard-print screen:
print "5"
Tkinter has built-in keypress events.
import Tkinter as tk
def keypress(event):
if event.keysym == 'Escape':
root.destroy()
x = event.char
if x == "w":
print "blaw blaw blaw"
elif x == "a":
print "blaha blaha blaha"
elif x == "s":
print "blash blash blash"
elif x == "d":
print "blad blad blad"
else:
print x
root = tk.Tk()
print "Press a key (Escape key to exit):"
root.bind_all('<Key>', keypress)
# don't show the tk window
root.withdraw()
root.mainloop()
In windows you could use the msvcrt module:
This is a standard Windows-specific extension module. It defines a function kbhit() which checks whether a keyboard hit is present, and getch() which gets one character without echoing it.
I'm not sure however if it can work with these two combined keypresses