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.

Files for defKey, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size defKey-1.0.1-py3-none-any.whl (15.3 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page