I was wondering if anyone knew of a way to scan for key presses in Python. It doesn't need to detect WHAT key is being pressed, just that one is being pressed. Also it needs to work with the console.
Brickmack 0 Newbie Poster
Recommended Answers
Jump to PostYou could use pygame.
http://pygame.org/docs/ref/event.html
Tips:
Remember to "pump" the event queue on each update.
Don't initalize a window, just use the console.
Jump to PostPython does not have a keypress capture so you have to use one provided by the system like termios.
import termios, sys, os TERMIOS = termios def getkey(): fd = sys.stdin.fileno() old = termios.tcgetattr(fd) new = termios.tcgetattr(fd) new[3] = new[3] & ~TERMIOS.ICANON & ~TERMIOS.ECHO new[6][TERMIOS.VMIN] = 1 …
Jump to PostNice one woooee
i think using new as a variable is not ok. I know you know that anyway that new is a reserved object.
In all, i like your sleakness . Bravo ;)
All 11 Replies
SgtMe 46 Veteran Poster Featured Poster
woooee 814 Nearly a Posting Maven
Gribouillis commented: nice snippet +4
richieking 44 Master Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
woooee 814 Nearly a Posting Maven
richieking 44 Master Poster
Gribouillis 1,391 Programming Explorer Team Colleague
richieking 44 Master Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
Gribouillis 1,391 Programming Explorer Team Colleague
richieking 44 Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.