Skip to main content

Non-blocking keybinds using threads

Project description


Non-blocking keybinds using threads.


  • Download with pip3 install defKey
  • Import with import defKey


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.


from defKey import defKey

def hello():

def goodbye():

def actualGoodbye():

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


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

defKey-1.0.0-py3-none-any.whl (15.3 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page