Skip to main content

defKey

Non-blocking keybinds using threads.

Setup

  • Download with pip3 install defKey
  • Import with import defKey

Usage

defKey allows the binding of keys to Python functions. When activated, defKey spawns a new thread which catches all keypresses (thus breaking input()) and, if they have been bound, spawns a new thread which executes the bound function. This is best for games and TUI programs.

Example

from defKey import defKey

def hello():
    print("hello")

def goodbye():
    print("goodbye")

def actualGoodbye():
    defKey.stop()

defKey.bind("h", hello)
defKey.bind("g", goodbye)
defKey.bind("q", actualGoodbye)

defKey.start()

You must call defKey.stop() before using input(). Binds will be retained and defKey can be restarted after.


All contributions are welcome by pull request or issue.

defKey is licensed under GNU General Public License v3.0. See LICENSE for full text.

Release files for defKey 1.0.1

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

Built distribution (wheel)

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

Release files / defKey-1.0.1-py3-none-any.whl

Download URL defKey-1.0.1-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62b9ee9f8248c3c61a8763878ad85120da842bbebb187b31d57978a6539ce5a9
BLAKE2b-256 checksum
How to use checksums
4360ac1991cb77000d0265d0c28900c1483540f137540c545b96951948b6f44b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.6

Release history Release notifications | RSS feed

This release

1.0.1 This release

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