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.
Jump to Post
Python 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 = new & ~TERMIOS.ICANON & ~TERMIOS.ECHO new[TERMIOS.VMIN] = 1 …
All 11 Replies
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.