Mar-02-2019, 02:12 AM
Something I found on the web a long time ago. There has to be other key capture programs as well.
import curses arrow_keys = {curses.KEY_UP:'up arrow', curses.KEY_DOWN:'down arrow', curses.KEY_LEFT:'left arrow', curses.KEY_RIGHT:'right arrow'} ## open a window/screen object stdscr = curses.initscr() curses.cbreak() stdscr.keypad(1) stdscr.addstr(0,10,"Hit 'q' to quit ") stdscr.refresh() key = '' while key != ord('q'): key = stdscr.getch() stdscr.addstr(20,25," ") stdscr.addch(20,25,key) stdscr.refresh() if key in arrow_keys: stdscr.addstr(18, 20, arrow_keys[key]) else: stdscr.addstr(18, 20, " ") curses.endwin()