-2

I've been searching the web on how to register a key down in python. All the websites I've tried all say to use pygame. Can i do it without pygame?

Funshine
  • 101
  • 2
  • 3
    To accept a "key down event" you'll need to be using some of API that models the idea of a window or context in which a "key down event" can happen. Python itself doesn't model this concept in the language or the API (aside from perhaps in the console API, [see here](http://stackoverflow.com/questions/983354/how-do-i-make-python-to-wait-for-a-pressed-key) maybe?). PyGame is one such API that provides windowing concepts. If you don't want to use PyGame you probably have to find another windowing API. –  Aug 06 '15 at 18:26

1 Answers1

0

Don't know what are your exact needs, but the curses module can achieve such things (console program):

from curses import wrapper

def main(stdscr):
    stdscr.clear()

    c = stdscr.getkey()

    if c == 'KEY_DOWN':
        stdscr.addstr(10, 2, 'key down detected')
    else:
        stdscr.addstr(10, 2, 'You pressed {}'.format(c))

    stdscr.refresh()
    stdscr.getkey()


wrapper(main)
stellasia
  • 5,372
  • 4
  • 23
  • 43