{"id":15142042,"url":"https://github.com/egj-moorington/circuitpython_button_handler","last_synced_at":"2026-01-08T19:18:34.495Z","repository":{"id":251668871,"uuid":"838088083","full_name":"EGJ-Moorington/CircuitPython_Button_Handler","owner":"EGJ-Moorington","description":"A CircuitPython helper library that handles different types of button presses.","archived":false,"fork":false,"pushed_at":"2024-09-02T13:27:29.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-09T22:40:59.536Z","etag":null,"topics":["circuitpython"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EGJ-Moorington.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-04T22:42:51.000Z","updated_at":"2024-09-02T13:22:08.000Z","dependencies_parsed_at":"2024-08-18T01:23:03.232Z","dependency_job_id":"ba3b209e-72af-4c26-b771-fee45abcd473","html_url":"https://github.com/EGJ-Moorington/CircuitPython_Button_Handler","commit_stats":null,"previous_names":["egj-moorington/circuitpython_button_handler"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EGJ-Moorington%2FCircuitPython_Button_Handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EGJ-Moorington%2FCircuitPython_Button_Handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EGJ-Moorington%2FCircuitPython_Button_Handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EGJ-Moorington%2FCircuitPython_Button_Handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EGJ-Moorington","download_url":"https://codeload.github.com/EGJ-Moorington/CircuitPython_Button_Handler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219867955,"owners_count":16555810,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["circuitpython"],"created_at":"2024-09-26T09:22:02.843Z","updated_at":"2026-01-08T19:18:34.483Z","avatar_url":"https://github.com/EGJ-Moorington.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Introduction\n============\n\n\n.. image:: https://readthedocs.org/projects/circuitpython-button-handler/badge/?version=latest\n    :target: https://circuitpython-button-handler.readthedocs.io/\n    :alt: Documentation Status\n\n\n\n.. image:: https://img.shields.io/discord/327254708534116352.svg\n    :target: https://adafru.it/discord\n    :alt: Discord\n\n\n.. image:: https://github.com/EGJ-Moorington/CircuitPython_Button_Handler/workflows/Build%20CI/badge.svg\n    :target: https://github.com/EGJ-Moorington/CircuitPython_Button_Handler/actions\n    :alt: Build Status\n\n\n.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json\n    :target: https://github.com/astral-sh/ruff\n    :alt: Code Style: Ruff\n\nThis helper library simplifies the usage of buttons with CircuitPython, by detecting and differentiating button inputs, returning a set of the inputs and calling their corresponding functions.\n\n\nDependencies\n=============\nThis driver depends on:\n\n* `Adafruit CircuitPython \u003chttps://github.com/adafruit/circuitpython\u003e`_\n\nPlease ensure all dependencies are available on the CircuitPython filesystem.\nThis is easily achieved by downloading\n`the Adafruit library and driver bundle \u003chttps://circuitpython.org/libraries\u003e`_\nor individual libraries can be installed using\n`circup \u003chttps://github.com/adafruit/circup\u003e`_.\n\nInstalling from PyPI\n=====================\n\nOn supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from\nPyPI \u003chttps://pypi.org/project/circuitpython-button-handler/\u003e`_.\nTo install for current user:\n\n.. code-block:: shell\n\n    pip3 install circuitpython-button-handler\n\nTo install system-wide (this may be required in some cases):\n\n.. code-block:: shell\n\n    sudo pip3 install circuitpython-button-handler\n\nTo install in a virtual environment in your current project:\n\n.. code-block:: shell\n\n    mkdir project-name \u0026\u0026 cd project-name\n    python3 -m venv .venv\n    source .env/bin/activate\n    pip3 install circuitpython-button-handler\n\nInstalling to a Connected CircuitPython Device with Circup\n==========================================================\n\nMake sure that you have ``circup`` installed in your Python environment.\nInstall it with the following command if necessary:\n\n.. code-block:: shell\n\n    pip3 install circup\n\nWith ``circup`` installed and your CircuitPython device connected use the\nfollowing command to install:\n\n.. code-block:: shell\n\n    circup install button_handler\n\nOr the following command to update an existing version:\n\n.. code-block:: shell\n\n    circup update\n\nUsage Example\n=============\n\nThis simple script showcases the usage of this library using a single button.\n\nSee the ``examples`` directory for more complex examples, including\ntriple presses, configuring button press delays, and supporting\nmultiple buttons.\n\n+---------------+\n| Button wiring |\n+===============+\n| GND           |\n+---------------+\n| D9            |\n+---------------+\n\n.. code-block:: python\n\n    import time\n\n    import board\n    from keypad import Keys\n\n    from button_handler import ButtonHandler, ButtonInitConfig, ButtonInput\n\n\n    def double_press():\n        print(\"Double press detected!\")\n\n\n    def short_press():\n        print(\"Short press detected!\")\n\n\n    def long_press():\n        print(\"Long press detected!\")\n\n\n    def hold():\n        print(\"The button began being held down!\")\n\n\n    actions = {\n        ButtonInput(ButtonInput.DOUBLE_PRESS, callback=double_press),\n        ButtonInput(ButtonInput.SHORT_PRESS, callback=short_press),\n        ButtonInput(ButtonInput.LONG_PRESS, callback=long_press),\n        ButtonInput(ButtonInput.HOLD, callback=hold),\n    }\n\n    scanner = Keys([board.D9], value_when_pressed=False)\n    button_handler = ButtonHandler(scanner.events, actions)\n\n\n    while True:\n        button_handler.update()\n        time.sleep(0.0025)\n\n\nDocumentation\n=============\nAPI documentation for this library can be found on `Read the Docs \u003chttps://circuitpython-button-handler.readthedocs.io/\u003e`_.\n\nFor information on building library documentation, please check out\n`this guide \u003chttps://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1\u003e`_.\n\nContributing\n============\n\nContributions are welcome! Please read our `Code of Conduct\n\u003chttps://github.com/EGJ-Moorington/CircuitPython_Button_Handler/blob/HEAD/CODE_OF_CONDUCT.md\u003e`_\nbefore contributing to help this project stay welcoming.\n\nThe easiest way to contribute to the repository is by `creating an issue \u003chttps://github.com/EGJ-Moorington/CircuitPython_Button_Handler/issues/new\u003e`_.\nAdd a concise title and then explain the issue or suggestion in more detail in the description. This is helpful even if you do not intend to develop a fix.\nIf you wish to do so, however, the repository must first be forked.\n\nForking the repository\n----------------------\n\nIn order to add commits to this repository, it must be `forked \u003chttps://github.com/EGJ-Moorington/CircuitPython_Button_Handler/fork\u003e`_ first.\nThis creates a copy of the repository you can edit. Make sure to deselect \"Copy the ``main`` branch only\".\n\nThe following steps explain the recommended approach to working on a fork. Git needs to be installed for this.\n\n1. **Clone the repository.**\n\n   Open a terminal in the directory where you wish to clone the fork, and then run the following:\n\n   .. code-block:: shell\n\n      git clone https://github.com/\u003cyour-github-username\u003e/CircuitPython_Button_Handler.git\n\n   Keep in mind the URL will be different if you changed the fork's name.\n\n2. **Set pre-commit up.**\n\n   This repository is set up with tools that assist in development by automatically formatting code, enforcing code standards\n   and fixing issues where possible.\n\n   For these tools to run automatically before committing, `pre-commit \u003chttps://pre-commit.com/\u003e`_\n   has to be installed. This can be done in a virtual environment in order to maintain a cleaner development setup.\n   Using a virtual environment isolates dependencies, ensuring they don't conflict with other projects.\n\n   To install ``pre-commit`` in a Python virtual environment:\n\n   1. **Ensure Python is installed in your system.**\n\n      You can check your version of `Python  \u003chttps://www.python.org/downloads/\u003e`_\n      with the following command:\n\n      .. code-block:: shell\n\n         python --version\n\n   2. **Create a Python virtual environment.**\n\n      To make a virtual environment of name ``.venv`` in the current directory, run:\n\n      .. code-block:: shell\n\n         python -m venv .venv\n\n   3. **Activate the virtual environment.**\n\n      * On Windows, run:\n\n        .. code-block:: shell\n\n           .\\.venv\\Scripts\\activate\n\n      * On Linux or macOS, run:\n\n        .. code-block:: shell\n\n           source .venv/bin/activate\n\n      To avoid repeating this step every time a terminal is opened in this directory,\n      configure your IDE to use the ``.venv`` virtual environment as the default interpreter.\n      In Visual Studio Code, this can be done by opening the command palette, typing\n      ``Python: Select Interpreter`` and selecting the ``.venv`` virtual environment.\n\n   4. **Install pre-commit.**\n\n      This can easily be achieved by executing:\n\n      .. code-block:: shell\n\n         pip install pre-commit\n         pre-commit install\n\n      After installing ``pre-commit``, the necessary hooks are installed on the next ``git commit``\n      or the next time ``pre-commit run`` is executed.\n\n3. **Create a new branch.**\n\n   To make a new branch from the ``dev`` branch:\n\n   .. code-block:: shell\n\n      git checkout dev\n      git branch -b \u003cbranch-name\u003e\n\n   **For consistency, please name the branch the same as the issue it addresses with the number of the issue preceding the name.\n   Write the name in** ``kebab-case`` **and with no special characters (underscores are allowed).**\n\n   For example, the branch for `issue #26 \u003chttps://github.com/EGJ-Moorington/CircuitPython_Button_Handler/issues/26\u003e`_\n   \"Update ``.readthedocs.yaml`` with Sphinx key\" was \"26-update-readthedocsyaml-with-sphinx-key\".\n\n4. **Commit your changes.**\n\n   After adding your changes, commit them to the new branch by executing:\n\n   .. code-block:: shell\n\n      git add .\n      git commit\n\n   When ready, push the changes to GitHub with the following commands:\n\n   .. code-block:: shell\n\n      git remote add origin https://github.com/\u003cyour-github-username\u003e/CircuitPython_Button_Handler.git\n      git push --set-upstream origin \u003cbranch-name\u003e\n\n5. **Open a pull request.**\n\n   Upon opening (or refreshing) the fork's GitHub page, a message should be visible close to the top of the page:\n\n      This branch is 1 commit ahead of ``EGJ-Moorington/CircuitPython_Button_Handler:main``.\n\n   Firstly, ensure the branch is up to date by pressing \"Sync fork\". Then, select \"Contribute\" \u003e \"Open pull request\".\n\n   The page will show \"Open a pull request\". Make sure to select ``base: dev`` and ``compare: \u003cyour-branch-name\u003e`` in the dropdowns.\n\n   Write a brief title and then explain the changes in the description. Finish by using a `closing keyword \u003chttps://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-     to-an-issue\u003e`_ for your issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegj-moorington%2Fcircuitpython_button_handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fegj-moorington%2Fcircuitpython_button_handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegj-moorington%2Fcircuitpython_button_handler/lists"}