Skip to main content

Global Hotkey Watcher for Reflex

Project description

Reflex Global Hotkey Watcher

Listens to hotkeys in the global scope and calls event handler as necessary.

from reflex_global_hotkey import global_hotkey_watcher

class State(rx.State):
    last_key_pressed: str = ""

    def on_key(self, keyname: str):
        self.last_key_pressed = keyname

def index():
    return rx.fragment(
        State.last_key_pressed,
        global_hotkey_watcher(
            on_key_down=State.on_key
        )
    )

You can special case on the event key:

global_hotkey_watcher(
    on_key_down=lambda key_name: rx.cond(
        rx.Var.create(
            ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]
        ).contains(key_name),
        State.on_key(key_name),
        rx.console_log("Invalid key!"),
    )
)

You can also special case on the second parameter:

from reflex_global_hotkey import global_hotkey_watcher
from reflex.event import KeyInputInfo

class State(rx.State):
    last_key_pressed: str = ""

    def on_key(self, keyname: str, keyinfo: KeyInputInfo):
        if not keyinfo["alt_key"]:
            self.last_key_pressed = keyname

def index():
    return rx.fragment(
        State.last_key_pressed,
        global_hotkey_watcher(
            on_key_down=State.on_key
        )
    )

The fields are defined in reflex.event:

class KeyInputInfo(TypedDict):
    """Information about a key input event."""

    alt_key: bool
    ctrl_key: bool
    meta_key: bool
    shift_key: bool

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

reflex_global_hotkey-1.2.3.tar.gz (60.1 kB view details)

Uploaded Source

Built Distribution

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

reflex_global_hotkey-1.2.3-py3-none-any.whl (2.3 kB view details)

Uploaded Python 3

File details

Details for the file reflex_global_hotkey-1.2.3.tar.gz.

File metadata

  • Download URL: reflex_global_hotkey-1.2.3.tar.gz
  • Upload date:
  • Size: 60.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.13

File hashes

Hashes for reflex_global_hotkey-1.2.3.tar.gz
Algorithm Hash digest
SHA256 e741ff628044dc8fd8249749a1af7b0b622e217ac530d2e508a187bbcd99dde9
MD5 76e240045850f34e5c813364961e4351
BLAKE2b-256 7a09fbca97b83d89bae114e21de78e1090ec47cb270a8924f506f2048d0eeedb

See more details on using hashes here.

File details

Details for the file reflex_global_hotkey-1.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for reflex_global_hotkey-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ecbf123ef932173f71e165f1050db7fe3b95fe62600bd6cd484e4f8959ba1526
MD5 17f81ebea9c532e13335cd3bdaae65bb
BLAKE2b-256 9a9da7f570a99e09aa86981f44543299b238b4d8ec8d994afbb03b9a959c8bc2

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