Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
curses library
#3
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()
Reply


Messages In This Thread
curses library - by autompav96 - Mar-01-2019, 04:06 PM
RE: curses library - by Larz60+ - Mar-01-2019, 10:44 PM
RE: curses library - by woooee - Mar-02-2019, 02:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I want to be able to scroll up in curses to see previous text. Caiden 1 800 Jul-28-2023, 01:15 PM
Last Post: deanhystad
  curses issue otalado 2 2,786 Jun-29-2021, 02:07 PM
Last Post: tmz
  How to make curses.border() use A_BOLD atttribute? pjfarley3 0 4,889 Feb-03-2021, 11:22 PM
Last Post: pjfarley3
  Curses script doesn't work wavic 1 4,192 Jan-08-2021, 09:11 PM
Last Post: wavic
  Why aren't all curses panel functions supported in python curses.panel? pjfarley3 2 2,701 Jul-22-2020, 11:08 PM
Last Post: pjfarley3
  curses key codes not working jgrillout 0 3,049 Feb-11-2019, 01:46 AM
Last Post: jgrillout
  Pretty table and curses? MuntyScruntfundle 0 2,924 Oct-16-2018, 10:22 AM
Last Post: MuntyScruntfundle
  curses.initscr doesn't work zaphod424 3 9,857 Feb-28-2018, 12:36 PM
Last Post: Gribouillis
  Curses could not find terminal Solstice 13 17,208 Jan-06-2018, 07:56 AM
Last Post: Gribouillis
  PyInstaller, how to create library folder instead of library.zip file ? harun2525 2 4,863 May-06-2017, 11:29 AM
Last Post: harun2525

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020