Skip to main content

Utilities to read single characters and key-strokes

Project description

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 in 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!

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 Distribution

readchar-0.2-test2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

readchar-0.2-test2.linux-i686.tar.gz (6.4 kB view details)

Uploaded Source

File details

Details for the file readchar-0.2-test2.tar.gz.

File metadata

File hashes

Hashes for readchar-0.2-test2.tar.gz
Algorithm Hash digest
SHA256 02854486881bded8d2b2a0a06ace70e10d835be673de0ba16382641a403c08f5
MD5 1b56456b8c8599939f27f5c80a778323
BLAKE2b-256 3ebe82e77aefbfe556bb5048edf5d099bb08e2feeb0e04a8824cb1133fc064b7

See more details on using hashes here.

File details

Details for the file readchar-0.2-test2.linux-i686.tar.gz.

File metadata

File hashes

Hashes for readchar-0.2-test2.linux-i686.tar.gz
Algorithm Hash digest
SHA256 be21e11f972d4ff1cdedd00b8321f2bf6c70e4ed129cbdb6d6a0578cd861af86
MD5 df26fbd20d6df1fae54561e5960020b0
BLAKE2b-256 bdf7a8e507600e7c2862de3f3fabdf1ed59089da597ec3b4f0b9b8b6aaa632d4

See more details on using hashes here.

Supported by

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