Skip to main content

Utilities to read single characters and key-strokes

Project description

See it at:

VERSION

DOWNLOADS

TESTS

COVERAGE

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.

Documentation

Installation

pip install readchar

The readchar library is compatible with python 2.6, 2.7, 3.2 and 3.3.

Usage

Usage example:

import readchar

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

API

There are just two methods:

readchar()

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

readkey()

Reads the next key-stroke from stdin, returning it as an 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 comparations and so on. This list is not enough tested and it can have mistakes, so use it carefully. Please, report them if found.

SO Support

Sadly, this library has only being probed on GNU/Linux. Please, if you can try it in another SO 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 https://github.com/magmax/python-readchar.git
  1. Create a virtual environment:

virtualenv venv
  1. Enter in the virtual environment

. venv/bin/activate
  1. Install dependencies

pip -r requirements.txt -r requirements-dev.txt
  1. Run tests

make

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

License

Copyright (c) 2014 Miguel Ángel García (@magmax9).

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.

Project details


Download files

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

Source Distributions

readchar-0.7.zip (10.4 kB view details)

Uploaded Source

readchar-0.7.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

readchar-0.7-py2-none-any.whl (8.2 kB view details)

Uploaded Python 2

File details

Details for the file readchar-0.7.zip.

File metadata

  • Download URL: readchar-0.7.zip
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for readchar-0.7.zip
Algorithm Hash digest
SHA256 ccae1f094eac3fb5ef6622dd3fbb25fd8b3b4b734ed835a36862b3f6916aa8aa
MD5 f51f478ccb22adc97e6ea08000bb03d6
BLAKE2b-256 a70e3ff91a79340cad7e40a859653c95da6061f56e35fdb473d07db0bb33f828

See more details on using hashes here.

File details

Details for the file readchar-0.7.tar.gz.

File metadata

  • Download URL: readchar-0.7.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for readchar-0.7.tar.gz
Algorithm Hash digest
SHA256 c3354162894634ff6a29a06a1cd04c92522f32b7bc6c17e247cf3bee27ee914c
MD5 c36427a423db9b5231bfd5f612c44795
BLAKE2b-256 61a9d552ab5bb2978b609a0acc917427fb0230ac923d92e32b817ef79908f6e3

See more details on using hashes here.

File details

Details for the file readchar-0.7-py2-none-any.whl.

File metadata

File hashes

Hashes for readchar-0.7-py2-none-any.whl
Algorithm Hash digest
SHA256 42195fa187ea91c1674c04fa8ccd2461eae508b0f219b41e97e692cd05d7f9ca
MD5 d647bc0ed286eb284ed9b003d93b12c9
BLAKE2b-256 a42b3ad24eecaa5c18d902641421ba1120b1730761bd80a0d1f77367d539137c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page