Method TriggerHotkeyAsync
- Namespace
- OBSStudioClient.Model
- Assembly
- OBSClient.dll
TriggerHotkeyAsync(string, string?, CancellationToken)
Triggers a hotkey of OBS Studio by its name, as if the key was pressed and released, and returns when OBS Studio has answered.
public Task TriggerHotkeyAsync(string name, string? context = null, CancellationToken cancellationToken = default)
Parameters
namestringThe name of the hotkey: one of GetHotkeysAsync(CancellationToken).
contextstringThe name of the source, output, encoder or service that has the hotkey, for a hotkey that belongs to one, or null for the hotkeys of OBS Studio itself.
cancellationTokenCancellationTokenA token that ends the wait. A change that was not sent yet is not sent.
Returns
- Task
A task that completes when OBS Studio has answered.
Remarks
What the hotkey does is up to OBS Studio, and the model learns of it as it learns of anything else that happens in OBS Studio: through its events. So the call does not wait for the model. obs-websocket advises to use another request wherever there is one: a method of the model that does the same is the better choice. See SetEnabledAsync(bool, CancellationToken) for the order of changes.
Exceptions
- ArgumentException
nameis empty.- ObsNotConnectedException
There is no connection to OBS Studio. Nothing was changed.
- ObsNotReadyException
OBS Studio is changing its scene collection, or did so after the call. Nothing was changed.
- ObsUnknownOutcomeException
OBS Studio did not answer in time, or the connection ended: it is not known whether it triggered the hotkey.
- ObsResponseException
OBS Studio refused the request: it has no hotkey of that name (ErrorCode is ResourceNotFound).
TriggerHotkeyAsync(ObsKey, KeyModifier, CancellationToken)
Presses a key in OBS Studio, with the modifier keys that you give, and releases it, so that the hotkeys of OBS Studio that this key sequence is set for react. It returns when OBS Studio has answered.
public Task TriggerHotkeyAsync(ObsKey key, KeyModifier modifiers = KeyModifier.None, CancellationToken cancellationToken = default)
Parameters
keyObsKeyThe key.
modifiersKeyModifierThe modifier keys that are held while the key is pressed.
cancellationTokenCancellationTokenA token that ends the wait. A change that was not sent yet is not sent.
Returns
- Task
A task that completes when OBS Studio has answered.
Remarks
OBS Studio does not say whether a hotkey reacted. See TriggerHotkeyAsync(string, string?, CancellationToken) for what to know about hotkeys, and SetEnabledAsync(bool, CancellationToken) for the order of changes.
Exceptions
- ObsNotConnectedException
There is no connection to OBS Studio. Nothing was changed.
- ObsNotReadyException
OBS Studio is changing its scene collection, or did so after the call. Nothing was changed.
- ObsUnknownOutcomeException
OBS Studio did not answer in time, or the connection ended: it is not known whether it pressed the key.
- ObsResponseException
OBS Studio refused the request: the key is none and no modifier is given (ErrorCode is CannotAct).