Skip to main content

Non-blocking keybinds using threads

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

defKey-1.0.1-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file defKey-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: defKey-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for defKey-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62b9ee9f8248c3c61a8763878ad85120da842bbebb187b31d57978a6539ce5a9
MD5 9e6c66003f608c13e6b23c3bf04b9e69
BLAKE2b-256 4360ac1991cb77000d0265d0c28900c1483540f137540c545b96951948b6f44b

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