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 works with python 2.7, 3.4, 3.5, 3.6 and Pypy.

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 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 https://github.com/magmax/python-readchar.git
  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

make

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

License

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.

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-3.0.5.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

readchar-3.0.5-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: readchar-3.0.5.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for readchar-3.0.5.tar.gz
Algorithm Hash digest
SHA256 d1f5b71e98c37b7f3b695fba9db978ab84f4f8a0ed879653d83e1d90a4c482c0
MD5 2c6cf39c20ea3ba66c17098d8e572bb6
BLAKE2b-256 8dff33df88cee8ab693302288fc7d2983e561bf7d78439b844407c976d52fa73

See more details on using hashes here.

File details

Details for the file readchar-3.0.5-py3-none-any.whl.

File metadata

  • Download URL: readchar-3.0.5-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for readchar-3.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 4c31210edfdf3e706d042c58feba2e8b6d5768b7f37002c5579fc473552f8fbb
MD5 c82a3b5988311c512025e0d8dd6921bf
BLAKE2b-256 400dd3819ead63911f2ff3f4ef6608c48b32bbc5f9d2d3934d520c7ab958be73

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