This code runs for 1 million iterations (about a few seconds on my machine), yet when I hold down a button, the # iterations where I hold down does not increase substantially.
import curses
stdscr = curses.initscr()
curses.cbreak()
curses.noecho()
stdscr.nodelay(1)
num_iters_nochar = 0
num_iters_char = 0
for i in range(10**6):
if stdscr.getch() == -1:
num_iters_nochar += 1
else:
num_iters_char += 1
curses.nocbreak()
curses.echo()
curses.endwin()
print num_iters_nochar , 'iterations with no input'
print num_iters_char , 'iterations with input'
Why doesn't the nodelay getch() accurately capture the button press?