Skip to content

masayukid/flet-modifier-key

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

flet-modifier-key

Custom control that allows you to detect the state of modifier keys (Shift, Ctrl, Alt, Meta) at any time.

Installation

Add dependency to pyproject.toml of your Flet app:

  • Git dependency

Link to git repository:

dependencies = [
  "flet==0.28.3",
  "flet-modifier-key @ git+https://github.com/masayukid/flet-modifier-key",
]
  • PyPi dependency

If the package is published on pypi.org:

dependencies = [
  "flet==0.28.3",
  "flet-modifier-key",
]

Example

import flet as ft
from flet_modifier_key import ModifierKey

def main(page: ft.Page):
    # Create a ModifierKey control
    mk = ModifierKey()
    
    def on_click(e):
        if mk.shift:
            print("Shift+Click detected!")
        elif mk.control:
            print("Ctrl+Click detected!")
        elif mk.alt:
            print("Alt+Click detected!")
        else:
            print("Normal click")
    
    page.add(
        mk,  # Add the ModifierKey control (it's invisible)
        ft.ElevatedButton("Click me", on_click=on_click)
    )

ft.app(target=main)

API Reference

ModifierKey

Properties

  • shift: bool - Returns True if the Shift key is currently pressed
  • control: bool - Returns True if the Control (Ctrl) key is currently pressed
  • alt: bool - Returns True if the Alt key is currently pressed
  • meta: bool - Returns True if the Meta key (Windows/Command) is currently pressed

Events

  • on_change - Triggered when any modifier key state changes

Use Cases

  • Multi-selection: Implement Shift+Click for range selection, Ctrl+Click for toggle
  • Custom scroll behavior: Zoom with Ctrl+Scroll, horizontal scroll with Shift+Scroll
  • Enhanced interactions: Different drag behaviors based on modifier keys
  • Keyboard shortcuts: Detect modifier keys for custom shortcuts
  • Canvas/Drawing apps: Different tools or behaviors when keys are held

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors