You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42-11Lines changed: 42 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -41,9 +41,13 @@ This guide will help you set up your first Stream Deck plugin using the library.
41
41
- Stream Deck software installed
42
42
- A valid `manifest.json` file for your plugin
43
43
44
-
### Creating an Action
44
+
### Creating Actions
45
45
46
-
An **Action** represents a specific functionality in your plugin. You can create multiple actions, each with its own set of event handlers.
46
+
The SDK provides two types of actions: `Action` and `GlobalAction`. Each represents functionality with different scopes in your plugin, determining how events are handled.
47
+
48
+
#### Regular Actions
49
+
50
+
An `Action` handles events that are specifically associated with it based on event metadata. When the Stream Deck sends an event, the action's handlers only run if the event metadata indicates it was triggered by or is intended for that specific action instance.
A `GlobalAction` runs its event handlers for all events of a given type, regardless of which action the events were originally intended for. Unlike regular Actions which only process events specifically targeted at their UUID, GlobalActions handle events meant for any action in the plugin, making them useful for implementing plugin-wide behaviors or monitoring.
62
+
63
+
```python
64
+
from streamdeck import GlobalAction
65
+
66
+
# Create a global action
67
+
my_global_action = GlobalAction()
68
+
```
69
+
70
+
Choose `GlobalAction` when you want to handle events at the plugin-scope (i.e. globally) without filtering by action, and `Action` when you need to process events specific to particular actions.
71
+
72
+
Note that an action with its UUID still needs to be defined in the manifest.json. Global Actions are an abstract component unique to this library — the global behavior is not how the Stream Deck software itself handles registering actions and publishing events.
73
+
55
74
### Registering Event Handlers
56
75
57
76
Use the `.on()` method to register event handlers for specific events.
58
77
59
78
```python
60
79
@my_action.on("keyDown")
61
-
defhandle_key_down(event):
62
-
print("Key Down event received:", event)
80
+
defhandle_key_down(event_data):
81
+
print("Key Down event received:", event_data)
63
82
64
83
@my_action.on("willAppear")
65
-
defhandle_will_appear(event):
66
-
print("Will Appear event received:", event)
84
+
defhandle_will_appear(event_data):
85
+
print("Will Appear event received:", event_data)
67
86
```
68
87
69
88
!!!INFO Handlers for action-specific events are dispatched only if the event is triggered by the associated action, ensuring isolation and predictability. For other types of events that are not associated with a specific action, handlers are dispatched without such restrictions.
@@ -159,22 +178,34 @@ Below is an example of the pyproject.toml configuration and how to run the plugi
159
178
160
179
## Simple Example
161
180
162
-
Below is a complete example that creates a plugin with a single action. The action handles the `keyDown` event and simply prints a statement that the event occurred.
181
+
Below is a complete example that creates a plugin with a single action. The action handles the `keyDown`and `applicationDidLaunch`event and simply prints a statement that an event occurred.
163
182
164
183
```python
165
184
# main.py
166
185
import logging
167
-
from streamdeck import Action, PluginManager, events
186
+
from streamdeck import Action, GlobalAction, PluginManager, events
0 commit comments