Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7964397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:52:52+00:00 2026-06-04T05:52:52+00:00

Possible Duplicate: Python read a single character from the user I am looking to

  • 0

Possible Duplicate:
Python read a single character from the user

I am looking to be able to control a robot with the arrow keys using python. And my idea was to implement code that looked something like this…

#!/usr/bin/env python
# control a robot using python
exit = 0
while exit == 0:
  keypress = ##get keypress, if no key is pressed, continue##
  if keypress == 'q':
    exit = 1
    break
  elif keypress == KEY_UP:
    ##robot move forward##
  elif keypress == KEY_DOWN:
    ##robot move backward##
print "DONE"

However the problem is that I do not know how to get the users input. And I cannot use a GUI based solution like pygame from what I have found because the robot does not use a display.

Any help is very much appreciated!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:52:53+00:00Added an answer on June 4, 2026 at 5:52 am

    A simple curses example. See the docs for the curses module for details.

    import curses
    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.addch(20,25,key)
        stdscr.refresh()
        if key == curses.KEY_UP: 
            stdscr.addstr(2, 20, "Up")
        elif key == curses.KEY_DOWN: 
            stdscr.addstr(3, 20, "Down")
    
    curses.endwin()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do you read from stdin in python I am new Python
Possible Duplicate: reading integers from binary file in python I've read the solution to
Possible Duplicate: Python code to pick out all possible combinations from a list? I
Possible Duplicate: Calling Python from Objective-C I'm a long-time Python programmer and short-time Cocoa
Possible Duplicate: Calling Python from JavaScript I have a test.py and test.js . I
Possible Duplicate: How many Python classes should I put in one file? Coming from
Possible Duplicate: python .rstrip removes one additional character What is the problem here? it
Possible Duplicate: Python analog of natsort function (sort a list using a “natural order”
Possible Duplicate: Python: How to read huge text file into memory To process a
Possible Duplicate: How to check dimensions of all images in a directory using python?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.