Giter Club home page Giter Club logo

python-readchar's Introduction

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.6, 2.7, 3.3, 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.

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
source venv/bin/activate
  1. Install dependencies
pip install -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, 2015 Miguel Angel Garcia (@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.

python-readchar's People

Contributors

ag-eitilt avatar boxed avatar brbsix avatar jwilk avatar kcsaff avatar magmax avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.