Skip to main content

Asynchronous keyboard input

Project description

askin

Asynchronous Keyboard Input

askin is a Python package that provides a simple way to get keyboard input asynchronously.

Installation

pip install askin

Usage

from askin import KeyboardController


class KeyState:
    def __init__(self) -> None:
        self.value = 0

    async def update(self, key: str) -> None:
        if key == "a":
            self.value += 1
        elif key == "b":
            self.value -= 1


async def key_handler(key: str) -> None:
    key_state.update(key)


async def default() -> None:
    print("Default! Resetting value to 0")
    key_state.value = 0


async def main() -> None:
    key_state = KeyState()
    controller = KeyboardController(key_handler=key_state.update, default=default, timeout=0.001)
    await controller.start()

    try:
        while True:
            print(key_state.value)
            await asyncio.sleep(0.1)
    finally:
        await controller.stop()


if __name__ == "__main__":
    asyncio.run(main())

Project details


Download files

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

Source Distribution

askin-0.0.2.tar.gz (5.3 kB view details)

Uploaded Source

File details

Details for the file askin-0.0.2.tar.gz.

File metadata

  • Download URL: askin-0.0.2.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for askin-0.0.2.tar.gz
Algorithm Hash digest
SHA256 13de3cc748c65aeae2608679fa4f3f43ad67b0f54d0d5651f7389686891c3767
MD5 2597dec86bb75cd5a645ab0508707fa6
BLAKE2b-256 c22cfda3a5c697a006f9bbb08fb4d9add070f56bdd372b0ee92bbba40901aaa6

See more details on using hashes here.

Provenance

The following attestation bundles were made for askin-0.0.2.tar.gz:

Publisher: publish.yml on WT-MM/asKin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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