Skip to content

MasterA5/Flet-Hoy-Key

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Flet HotKey — Professional Hotkey Manager for Flet

Credits To Wanna-Pizza Developer

Easily bind global keyboard shortcuts in your Flet applications with a flexible, event-driven HotKey system. Supports Ctrl, Shift, Alt, and multi-modifier combinations such as:

  • ctrl+f
  • ctrl+shift+d
  • alt+shift+x
  • ctrl+alt+shift+s

Designed for clarity, extensibility, and clean integration with any Flet project.


🚀 Features

  • ✔️ Simple API: manager.add("ctrl+f", callback)
  • ✔️ Support for multiple modifiers
  • ✔️ Detailed event object (HotKeyEvent)
  • ✔️ Works anywhere in the page (global keyboard listener)
  • ✔️ Lightweight and dependency-free
  • ✔️ Supports multiple hotkeys at once
  • ✔️ Clean parsing logic for hotkey strings

📦 Installation

Copy the HotKey folder into your project directory.

from HotKey import *

📘 Basic Example

from HotKey import *
from flet import *

def main(page: Page):

    manager = HotKeysManager(page)

    text = Text("Hello World")

    alert = AlertDialog(
        title=Text("Change Text Value"),
        content=Column(
            controls=[
                TextField(
                    value=text.value,
                    on_change=lambda e: (
                        setattr(text, "value", e.control.value),
                        page.update()
                    ),
                    multiline=True,
                    autofocus=True
                ),
                Row(
                    controls=[
                        ElevatedButton(
                            text="Change Text",
                            on_click=close_alert
                        )
                    ],
                    alignment=MainAxisAlignment.END
                )
            ],
            tight=True
        )
    )

    page.overlay.append(alert)

    def close_alert():
        alert.open = False
        page.update()

    # -------------------------
    # callback with EVENT
    # -------------------------
    def change_text_value(event: HotKeyEvent):
        print("Hotkey:", event.hotkey)
        print("Key pressed:", event.key)
        print("Modifiers:", event.modifiers)
        print("Time:", event.timestamp)

        alert.open = not alert.open
        page.update()

    # Adding the hoykey combination to manager
    manager.add("ctrl+f", change_text_value)

    page.add(text)

app(target=main)

🎯 HotKeyEvent Object

Your callback receives a HotKeyEvent instance containing:

Attribute Description
page The Flet Page object
hotkey The hotkey string that was triggered ("ctrl+f")
key The actual key pressed ("f")
modifiers A set of modifiers like {"ctrl", "shift"}
timestamp Time when the hotkey fired

🧠 How Hotkeys Are Parsed

The system supports:

  • ctrl
  • shift
  • alt
  • Any normal key (letters, numbers, F-keys)

Example valid combinations:

ctrl+a
ctrl+shift+e
alt+v
alt+shift+f1
ctrl+alt+shift+p

Order does not matter — shift+ctrl+p is equivalent to ctrl+shift+p.


Register Multiple Hotkeys

manager.add("ctrl+n", new_file)
manager.add("ctrl+shift+s", save_as)
manager.add("alt+q", quit_app)

🗑️ Remove a Hotkey

manager.remove("ctrl+f")

🧩 Advanced Use: Anonymous Callbacks

manager.add("ctrl+shift+x", lambda e: print("Triggered!"))

🛡️ Notes & Limitations

  • Hotkeys work only when the page is focused.
  • Hotkeys can conflict with browser/system shortcuts.
  • On mobile platforms, hotkeys may not be supported.

❤️ Contribute

Feel free to extend or improve the HotKey system. PRs and suggestions are welcome!

About

A Simple Hot Key Helper For Flet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages