Skip to content

Commit d1291b1

Browse files
committed
Update README.md with documentation for Global Actions
1 parent 72c526a commit d1291b1

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

README.md

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ This guide will help you set up your first Stream Deck plugin using the library.
4141
- Stream Deck software installed
4242
- A valid `manifest.json` file for your plugin
4343

44-
### Creating an Action
44+
### Creating Actions
4545

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.
4751

4852
```python
4953
from streamdeck import Action
@@ -52,18 +56,33 @@ from streamdeck import Action
5256
my_action = Action(uuid="com.example.myplugin.myaction")
5357
```
5458

59+
#### Global Actions
60+
61+
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+
5574
### Registering Event Handlers
5675

5776
Use the `.on()` method to register event handlers for specific events.
5877

5978
```python
6079
@my_action.on("keyDown")
61-
def handle_key_down(event):
62-
print("Key Down event received:", event)
80+
def handle_key_down(event_data):
81+
print("Key Down event received:", event_data)
6382

6483
@my_action.on("willAppear")
65-
def handle_will_appear(event):
66-
print("Will Appear event received:", event)
84+
def handle_will_appear(event_data):
85+
print("Will Appear event received:", event_data)
6786
```
6887

6988
!!!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
159178

160179
## Simple Example
161180

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.
163182

164183
```python
165184
# main.py
166185
import logging
167-
from streamdeck import Action, PluginManager, events
186+
from streamdeck import Action, GlobalAction, PluginManager, events
168187
169188
logger = logging.getLogger("myaction")
170189
171190
# Define your action
172191
my_action = Action(uuid="com.example.myplugin.myaction")
173192
174-
# Register event handlers
193+
# Define your global action
194+
my_global_action = GlobalAction()
195+
196+
# Register event handlers for regular action
197+
@my_action.on("applicationDidLaunch")
198+
def handle_application_did_launch(event_data: events.ApplicationDidLaunch):
199+
logger.debug("Application Did Launch event recieved:", event_data)
200+
175201
@my_action.on("keyDown")
176-
def handle_key_down(event):
177-
logger.debug("Key Down event received:", event)
202+
def handle_key_down(event_data: events.KeyDown):
203+
logger.debug("Key Down event received:", event_data)
204+
205+
# Register event handlers for global action
206+
@my_global_action.on("keyDown")
207+
def handle_global_key_down(event_data: events.KeyDown):
208+
logger.debug("Global Key Down event received:", event_data)
178209
```
179210

180211
```toml

0 commit comments

Comments
 (0)