Archived
This project has been archived by its maintainers, and is no longer receiving any updates.
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
Metadata
Release files for reflex-global-hotkey 1.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| reflex_global_hotkey-1.2.3.tar.gz | 60.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| reflex_global_hotkey-1.2.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 62.5 kB
Release files / reflex_global_hotkey-1.2.3.tar.gz
| Download URL | reflex_global_hotkey-1.2.3.tar.gz |
|---|---|
| Size | 60.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e741ff628044dc8fd8249749a1af7b0b622e217ac530d2e508a187bbcd99dde9
|
|
BLAKE2b-256 checksum How to use checksums |
7a09fbca97b83d89bae114e21de78e1090ec47cb270a8924f506f2048d0eeedb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.7.13
|
Release files / reflex_global_hotkey-1.2.3-py3-none-any.whl
| Download URL | reflex_global_hotkey-1.2.3-py3-none-any.whl |
|---|---|
| Size | 2.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ecbf123ef932173f71e165f1050db7fe3b95fe62600bd6cd484e4f8959ba1526
|
|
BLAKE2b-256 checksum How to use checksums |
9a9da7f570a99e09aa86981f44543299b238b4d8ec8d994afbb03b9a959c8bc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.7.13
|