Skip to content

Subscribing to events

BarRaider edited this page Mar 24, 2021 · 2 revisions

Main Events

When implementing the PluginBase class, you automatically subscribe to the 6 main events (and implement the logic as needed):

  • Constructor - Your constructor is called when the WillAppear Stream Deck event is triggered, thus notifying you that your action is now displayed on the device.
  • KeyPressed - Called when the Stream Deck key this action is on is pressed
  • KeyReleased - Called when the Stream Deck key this action is on is released
  • ReceivedSettings - Called when the Property Inspector sends new settings
  • ReceivedGlobalSettings - Called when new the Global Settings is refreshed (See Global Settings section for more details)
  • Dispose - Called when the WillDisappear Stream Deck event is triggered, thus notifying you that your action is no longer active and you should dispose all resources.

OnTick - The OnTick event is called once every 1000 ms and can be used for updating the title/image of the key.

Additional Events

In addition to those, a list with the rest of the Stream Deck events is available here. You can subscribe to them using the Connection object in the plugin.
IMPORTANT: Remember to unsubscribe in the Dispose() function as shown below:

Example

// Subscribe in Constructor

public MyPlugin(SDConnection connection, InitialPayload payload) : base(connection, payload)
{
	...
	...

	Connection.OnApplicationDidLaunch += Connection_OnApplicationDidLaunch;
	Connection.OnApplicationDidTerminate += Connection_OnApplicationDidTerminate;
	Connection.OnDeviceDidConnect += Connection_OnDeviceDidConnect;
	Connection.OnDeviceDidDisconnect += Connection_OnDeviceDidDisconnect;
	Connection.OnPropertyInspectorDidAppear += Connection_OnPropertyInspectorDidAppear;
	Connection.OnPropertyInspectorDidDisappear += Connection_OnPropertyInspectorDidDisappear;
	Connection.OnSendToPlugin += Connection_OnSendToPlugin;
	Connection.OnTitleParametersDidChange += Connection_OnTitleParametersDidChange;
}

...
	
// Unsubscribe in Dispose
public override void Dispose()
{
	Connection.OnApplicationDidLaunch -= Connection_OnApplicationDidLaunch;
	Connection.OnApplicationDidTerminate -= Connection_OnApplicationDidTerminate;
	Connection.OnDeviceDidConnect -= Connection_OnDeviceDidConnect;
	Connection.OnDeviceDidDisconnect -= Connection_OnDeviceDidDisconnect;
	Connection.OnPropertyInspectorDidAppear -= Connection_OnPropertyInspectorDidAppear;
	Connection.OnPropertyInspectorDidDisappear -= Connection_OnPropertyInspectorDidDisappear;
	Connection.OnSendToPlugin -= Connection_OnSendToPlugin;
	Connection.OnTitleParametersDidChange -= Connection_OnTitleParametersDidChange;
	Logger.Instance.LogMessage(TracingLevel.INFO, "Destructor called");
}

Next Topic: Global Settings