0

I just started using the asciimatics library, and I want it to take keyboard input. My code thus far is:

from asciimatics import *
import time

def demo(screen):
    while True:
        x = screen.get_event()
        if x:
            screen.print_at(str(x), 0, 0)
            screen.refresh()

Screen.wrapper(demo)

But when i, say, try to type "e" it gives me this:

KeyboardEvent: 101) 0

It collects these random numbers on keyboard and mouse events. (I only want keyboard events).

I want it to record keyboard input similar to input. Edit: does it need to be something "chr"?

Macaroonman
  • 61
  • 1
  • 10

1 Answers1

1

As documented here, get_event returns Events. To get the string value of the key pressed, use chr(x.key_code) if for any KeyboardEvent.

Peter Brittain
  • 13,489
  • 3
  • 41
  • 57