Skip to content Skip to sidebar Skip to footer

How To Get Input As A Left Arrow Key?

I want to get the left and right arrow key as a one of the input. How can i get it? Is there any way?

Solution 1:

That's how you can do it with ncurses. Unlike TkInter, X11 is not required.

#! /usr/bin/pythonimport curses

screen = curses.initscr()
try:
    curses.noecho()
    curses.curs_set(0)
    screen.keypad(1)
    screen.addstr("Press a key")
    event = screen.getch()
finally:
    curses.endwin()

if event == curses.KEY_LEFT:
    print("Left Arrow Key pressed")
elif event == curses.KEY_RIGHT:
    print("Right Arrow Key pressed")
else:
    print(event)

Solution 2:

This is possible with:

CursesUrwidPyGame

Tkinter is in the standard library.

Post a Comment for "How To Get Input As A Left Arrow Key?"