Dal python docs:
import termios, fcntl, sys, os
fd = sys.stdin.fileno()
oldterm = termios.tcgetattr(fd)
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, newattr)
oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
try:
while 1:
try:
c = sys.stdin.read(1)
print "Got character", `c`
except IOError: pass
finally:
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
Questo funziona solo per varianti di Unix però. Non penso ci sia un modo multipiattaforma.
fonte
2009-09-08 16:37:11
Dov'è il tasto "qualsiasi"? Non ne ho uno sulla tastiera –
+1 per l'uso ovvio di un cliché. –
@Patrick Perché non hai il tasto "uno" sulla tastiera? Il resto dei numeri va bene? Hai perso "1"? O trovi divertente entrare in "1" tramite combinazioni di tasti ASCII? – AneesAhmed777