Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Library to easily read single chars and keystrokes.
Born as a python-inquirer requirement.
simply install it via pip
:
pip install readchar
Or download the source code from PyPi.
Simply read a character or keystroke:
import readchar
key = readchar.readkey()
React to different kinds of key-presses:
from readchar import readkey, key
while True:
k = readkey()
if k == "a":
# do stuff
if k == key.DOWN:
# do stuff
if k == key.ENTER:
break
There are just two methods:
readchar.readchar() -> str
Reads one character from stdin
, returning it as a string with length 1. Waits until a
character is available.
As only ASCII characters are actually a single character, you usually want to use the next function, that also handles longer keys.
readchar.readkey() -> str
Reads the next keystroke from stdin
, returning it as a string. Waits until a keystroke
is available.
A keystroke can be:
readchar()
. These include:
Note CTRL+C will not be returned by
readkey()
, but instead raise aKeyboardInterupt
. If you want to handle it yourself, usereadchar()
.
readchar.key
moduleThis submodule contains a list of available keys to compare against. The constants are
defined depending on your operating system, so it should be fully portable. If a key is
listed here for your platform, readkey()
can read it, and you can compare against it.
readchar.config
classThis static class contains configurations for readchar
. It holds constants that are
used in other parts of the code as class attributes. You can override/change these to
modify its behaviour. Here is a description of the existing attributes:
INTERRUPT_KEYS
List of keys that will result in readkey()
raising a KeyboardInterrupt
.
Default: [key.CTRL_C]
This library actively supports these operating systems:
Some operating systems are enabled, but not actively tested or supported:
Theoretically every Unix based system should work, but they will not be actively tested. It is also required that somebody provides initial test results before the OS is enabled and added to the list. Feel free to open a PR for that.
Thank you!
You have an issue problem or found a bug? You have a great new idea or just want to fix a typo? Great :+1:. We are happy to accept your issue or pull request, but first, please read our contribution guidelines. They will also tell you how to write code for this repo and how to properly prepare an issue or a pull request.
Copyright (c) 2014-2022 Miguel Ángel García
FAQs
Library to easily read single chars and key strokes
We found that readchar demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.