Skip to main content

Dokkey is a Python package designed to detect keypresses on Windows

Project description

Dokkey

Dokkey is a lightweight Python package designed to detect key presses on Windows. It captures keyboard input and returns the ASCII code of the key pressed. This package has been tested on Windows 11.


Features

  • Detects keypresses on Windows.
  • Returns the ASCII code of the key pressed.
  • Lightweight and easy to integrate into your projects.

Requirements

  • Python 3.7 or higher
  • Windows OS (Tested on Windows 11)

Installation

Install the package using pip:

pip install dokkey

Usage

Here is an example of how to use Dokkey:

import signal
import dokkey

def cleanup_and_exit(signum, frame):
    try:
        dokkey.uninstall_hook()
    except Exception as e:
        print(f">>> Error during cleanup: {e}")
    finally:
        print(">>> Exiting gracefully.")
        exit(0)

signal.signal(signal.SIGINT, cleanup_and_exit)

# Install the hook and run the message loop
def on_key_press(key_code):
    print(f">>> Key pressed: {key_code}")

print("Listening for key presses. Press Ctrl+C to stop.")
try:
    dokkey.install_hook(on_key_press)
    dokkey.run_message_loop()
except Exception as e:
    print(f">>> Error: {e}")
finally:
    dokkey.uninstall_hook()

Output Example

Listening for key presses. Press Ctrl+C to stop.
Key pressed: 65  # (A key)
Key pressed: 98  # (b key)

How It Works

Dokkey leverages Windows APIs to capture global keyboard events and converts the input to ASCII codes. It ensures minimal interference with other running applications.

Limitations

This package works only on Windows. It may require administrator privileges for certain use cases.

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.

Local Development

To set up a local development environment, follow these steps:

  1. Create and activate a virtual environment:
    python -m venv venv
    venv/Scripts/activate
    
  2. Build & install the project
    python setup.py build
    python setup.py install
    

The module is now installed in the virtual environment. You can test it by running the example script:

python examples/example.py

License

This project is licensed under the Apache-2.0 License. See the LICENSE file for details.

Author

Developed by Sekiraw

Acknowledgements

Thanks to the Python and Windows development communities for providing tools and resources to make this project possible.

This styling ensures clarity, proper sectioning, and good readability. Let me know if you`d like any further adjustments!

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

dokkey-1.2.2.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

dokkey-1.2.2-cp312-cp312-win_amd64.whl (12.5 kB view details)

Uploaded CPython 3.12Windows x86-64

File details

Details for the file dokkey-1.2.2.tar.gz.

File metadata

  • Download URL: dokkey-1.2.2.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for dokkey-1.2.2.tar.gz
Algorithm Hash digest
SHA256 cf5eea87735d5904ea5f3f2d515b5321cf8786d64800425532a4dd7a786609e1
MD5 799f53dc827ee272ad03a3baaeb0d90a
BLAKE2b-256 c2a6eb3b0a1069645f48691f72f09094fbfec954c2831817da1f2b378558c1de

See more details on using hashes here.

File details

Details for the file dokkey-1.2.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: dokkey-1.2.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for dokkey-1.2.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7f1f8a5a465cf5d698cfddd28e58b31ae44c680ae15b5f044f02fdfbe17ed99b
MD5 9329d177386830bcdb774035dae5b7e3
BLAKE2b-256 7f6de0e3b5112d3d74aee614829986b019094e8ae58f683d472b37e3f3239d7c

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