Skip to main content

Utilities to read single characters and key-strokes

Project description

See it at:

Latest PyPI version Number of PyPI downloads Travis results Coveralls results_

Library to easily read single chars and key strokes.

Goal and Philosophy

Born as a python-inquirer requirement.

The idea is to have a portable way to read single characters and key-strokes.



pip install readchar

The readchar library works with python 2.7, 3.4, 3.5, 3.6 and Pypy.


Usage example:

import readchar

c = readchar.readchar()
key = readchar.readkey()


There are just two methods:


Reads the next char from stdin, returning it as a string with length 1.


Reads the next key-stroke from stdin, returning it as a string.

A key-stroke can have:

  • 1 character for normal keys: ‘a’, ‘z’, ‘9’…
  • 2 characters for combinations with ALT: ALT+A, …
  • 3 characters for cursors: ->, <-, …
  • 4 characters for combinations with CTRL and ALT: CTRL+ALT+SUPR, …

There is a list of previously captured chars with their names in readchar.key, in order to be used in comparisons and so on. This list is not enough tested and it can have mistakes, so use it carefully. Please, report them if found.

OS Support

Sadly, this library has only being probed on GNU/Linux. Please, if you can try it in another OS and find a bug, put an issue or send the pull-request.

Thank you!

How to contribute

You can download the code, make some changes with their tests, and make a pull-request.

In order to develop or running the tests, you can do:

  1. Clone the repository.
git clone
  1. Create a virtual environment:
virtualenv venv
  1. Enter in the virtual environment
source venv/bin/activate
  1. Install dependencies
pip install -r requirements-test.txt
  1. Run tests

Please, Execute the tests before any pull-request. This will avoid invalid builds.


Copyright (c) 2014-2021 Miguel Angel Garcia (@magmax_en).

Based on previous work on gist getch()-like unbuffered character reading from stdin on both Windows and Unix (Python recipe), started by Danny Yoo.

Licensed under the MIT license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for readchar, version 3.0.4
Filename, size File type Python version Upload date Hashes
Filename, size readchar-3.0.4-py3-none-any.whl (7.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size readchar-3.0.4.tar.gz (6.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page