Asciimatics Keyboard Input

596 Views Asked by At

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"?

1

There are 1 best solutions below

0
On

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.