Skip to main content

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

Metadata

Release files for getchlib 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for getchlib 2.0.1
File Size Uploaded
getchlib-2.0.1.tar.gz 14.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for getchlib 2.0.1
File Interpreter ABI Platform
getchlib-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 30.1 kB

Release files / getchlib-2.0.1.tar.gz

Download URL getchlib-2.0.1.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
64b7a884dd0c656a902b6bdbe8b65a32dbfc62a4e29d480b15590406afe3a5a5
BLAKE2b-256 checksum
How to use checksums
5251e908dffa3d5eecba500d2e17d4679ce5517b283c12a783404f4d9959e18e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / getchlib-2.0.1-py3-none-any.whl

Download URL getchlib-2.0.1-py3-none-any.whl
Size 15.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0374b76ca2d0d6f87ea31cdaccd51870e137208f3e0bb15e5e77e84b5f57b947
BLAKE2b-256 checksum
How to use checksums
58f2a07245f57f2379549734b5788bbdd41df9268769de922801a9ba3ef5c1dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

1 release file

1.0.13

1 release file

1.0.12

1 release file

1.0.11

1 release file

1.0.10

1 release file

1.0.9

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page