Reputation: 25
i have this simple program . there is no error in the program also the when i press q the program exits
import curses
def main(stdscr):
while 1:
Key = stdscr.getch()
if Key == curses.KEY_UP:
stdscr.addstr(0,0,'u pressed up key ')
stdscr.refresh()
elif Key == curses.KEY_DOWN:
stdscr.addstr(0,0,'u pressed down key')
stdscr.refresh()
elif Key == curses.KEY_LEFT:
stdscr.addstr(0,0,'u pressed left key')
stdscr.refresh()
elif Key == curses.KEY_RIGHT:
stdscr.addstr(0,0,'u pressed right key')
stdscr.refresh()
elif Key == ord('q'):
break
curses.wrapper(main)
Upvotes: 1
Views: 1195
Reputation: 30206
If getkey
on arrow keys is giving you letters {A|B|C|D} and getch
is giving your their numeric equivalents, call .keypad(True)
on the window from which you're reading. doc
stdscr.keypad(True)
key = stdscr.getch()
stdscr.addstr(0, 0, '%s' % key == curses.KEY_UP)
This will have curses interpret the arrow keys' entire escape sequence for you.
Upvotes: 2