Skip to main content

Library for reading key presses

Project description

getchlib - library for reading key presses

Overview

getchlib is library for reading key presses and assigning hotkeys. Warning: update 2.0.0 introduced breaking changes. Please update your code or revert to an earlier version if problems arise.

Features

  • Full Unicode support (Linux only)
  • Blocking and non-blocking key press reading
  • Cross-platform support
  • Support for modifier keys: CTRL, ALT, SHIFT, META.
  • Support for special and function keys.
  • Non-interruptable key press reading support ( cannot be interrupted by CTRL-C, returns the key instead)
  • Fully typed

Installation

pip install getchlib

Usage

Key Presses

Blocking

import getchlib
key=getchlib.getkey()

Waits until user presses a key.

Non-Blocking

import getchlib
key=getchlib.getkey(blocking=False)

Returns the currently pressed key. On Linux, you can also specify a timeout for the key using the tout argument.

Non-interruptable

import getchlib
key=getchlib.getkey(catch=True)

Buffering

If multiple key presses are registered at the same time, they are stored into an internal buffer. Subsequent calls to getkey() read from this buffer. In case this behaviour is not desired, you can force getkey() to read a new key using the buffer=False argument.

KeyboardEvent

getkey() returns a KeyboardEvent object. For backwards compatibility, it subclasses str - this means that you likely won't have to change your code, if it relied on the old API. It has the following attributes:

  • code: str: the raw key code outputted by the terminal
  • key: getchlib.Key | str: a member of the getchlib.Key enum if it's a special key, a string otherwise.
  • modifiers: set[getchlib.KeyboardModifier]: a set of one of getchlib.KeyboardModifier.SHIFT, getchlib.KeyboardModifier.CTRL, getchlib.KeyboardModifier.ALT, getchlib.KeyboardModifier.META

Windows Disclaimer

The Windows version of this package has only been tested on Wine. Bugs are possible.

License

getchlib is licensed under the GPL 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

getchlib-2.0.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

getchlib-2.0.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file getchlib-2.0.0.tar.gz.

File metadata

  • Download URL: getchlib-2.0.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for getchlib-2.0.0.tar.gz
Algorithm Hash digest
SHA256 216aa851d3056050edce3e13149b1e3b7346a036e38e640cf50de631296ca04a
MD5 12d5d14eea8ecfcc0081af2d218e1a71
BLAKE2b-256 342f98dfe0d42313ddec9e03178ffbc9cc28c3bef83894c245bc2337b1d4be75

See more details on using hashes here.

File details

Details for the file getchlib-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: getchlib-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for getchlib-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06057bebb3063e9ffc9f465dbaba5ca402703ad4ce3caa555db4a27b2b574fd5
MD5 e667b8c8a416b059a7bd31d4aa086bdc
BLAKE2b-256 cf62a995147984f430ed9f1e3c7af1645d4c2274a41cd3dfc43393f0e92fa3e8

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