Get just one char from long keypress python curses [accepted] -
hi i'm writing program in python curses , need 1 char long keypress. (in other words need if keep pressing down key program has char function getchar() once). need because want prevent curses refreshing many times windows. i'm not giving code cause in italian , long. thank you.
one solves problem by
- setting variable record fact character read
- reading character
- if no character available (within timeout, instance), stop reading
- if no character read yet, record fact 1 read (as remembering character)
- go step 2, read again
simply reading terminal not cause curses work (it refresh on each read, anyway). have work if program modifies screen. (assuming have turned echo
off), there no need worry number of calls refresh
.
regarding comment "it has clear , refresh box": there choices (per documentation):
- window.erase() clears window, but
- window.clear() erase(), causes whole window repainted upon next call refresh().
avoid using window.clear() unless intend repainting whole window, because slower, , visually distracting.
by way, curses function called getch
, not getchar
. latter may not work curses.
Comments
Post a Comment