-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentify-keys
More file actions
executable file
·58 lines (47 loc) · 1.55 KB
/
Copy pathidentify-keys
File metadata and controls
executable file
·58 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
"""Press each key to see its index flash on the button. Ctrl+C to quit."""
from __future__ import annotations
import sys
import time
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
ROOT = Path(__file__).resolve().parent
sys.path.insert(0, str(ROOT))
import streamdeck_app.patch_streamdeck # noqa: F401
from StreamDeck.DeviceManager import DeviceManager
from StreamDeck.ImageHelpers import PILHelper
def main() -> None:
decks = DeviceManager().enumerate()
if not decks:
raise SystemExit("No Stream Deck found")
deck = decks[0]
deck.open()
deck.reset()
deck.set_brightness(60)
blank = PILHelper.to_native_key_format(
deck, PILHelper.create_key_image(deck, "#161a22")
)
for i in range(deck.key_count()):
deck.set_key_image(i, blank)
def on_key(d, key: int, state: bool) -> None:
if not state:
deck.set_key_image(key, blank)
return
img = PILHelper.create_key_image(deck, "#2d6cdf")
draw = ImageDraw.Draw(img)
draw.text((20, 40), str(key), fill="white")
deck.set_key_image(key, PILHelper.to_native_key_format(deck, img))
print(f"key pressed: {key}")
sys.stdout.flush()
deck.set_key_callback(on_key)
print(f"Connected: {deck.deck_type()} ({deck.key_count()} keys). Press keys...")
try:
while deck.is_open():
time.sleep(0.1)
except KeyboardInterrupt:
pass
finally:
deck.reset()
deck.close()
if __name__ == "__main__":
main()