Hot Key Service
Overview
IHotKeyService is the central component responsible for global keyboard shortcuts. It listens for key presses on the application window, matches them against the set of registered hot key actions, and executes the matching action against the currently focused view model.
Every shortcut is described by an IHotKeyAction. The service also persists user overrides: when a user rebinds an action, the new gesture is saved to the application configuration; default gestures are not stored, so resetting a binding simply removes the override.
Key Features
Global Dispatch: Subscribes to
KeyDownon the currentTopLeveland routes each gesture to a matching action.Context Awareness: An action is evaluated against the currently focused view model (
Shell.Navigation.SelectedControl). A typed action (HotKeyAction<T>) runs when that view model — or one of its routable ancestors — is of typeT; otherwise it is skipped.Rebinding & Persistence: Gestures can be changed at runtime through the indexer. Overrides are stored in
HotKeyServiceConfig; assigning the default gesture (ornull) removes the override.CanExecute Tracking:
ObserveCanExecutereports whether an action can currently run — convenient for enabling or disabling UI elements.
Hot Key Actions
A shortcut is defined by implementing IHotKeyAction (which extends IHotKeyInfo). The framework provides the HotKeyAction<T> base class that targets a capability interface T: the action can execute when the focused view model — or any of its ancestors in the routable tree — is of type T, and InternalExecute receives that matched instance already cast.
The framework registers a default set of actions out of the box, including SaveAction, SaveAsAction, UndoAction, RedoAction, SearchAction, RefreshAction, ClosePageAction, OpenFileAction, OpenHomePageAction, CancelAction and ClearAction.
Registration
The service and its default actions are registered by the core services, so in a normal app you do not register them yourself. A module that needs an extra shortcut just adds its own action — the service and the built-in actions are already in place:
If you compose the service registration yourself, pass a configure delegate to RegisterHotKeys and call RegisterDefault() inside it to keep the built-in actions:
Rebinding a Hot Key
Use the indexer to read or change the gesture bound to an action. Assigning null restores the default:
API
IHotKeyService
Dispatches global keyboard shortcuts and stores user overrides.
Property | Type | Description |
|---|---|---|
|
| Emits every recognized gesture before it is dispatched to an action. |
|
| Enables or disables global hot key handling. |
|
| All registered actions. |
|
| Emits when an action's gesture changes. |
Indexer | Type | Description |
|---|---|---|
|
| Gets or sets the gesture bound to an action id. Setting |
Method | Return Type | Description |
|---|---|---|
|
| Reports whether the action can execute for the current context. |
IHotKeyService.this[string hotKeyId]
Parameter | Type | Description |
|---|---|---|
|
| The action identifier. |
IHotKeyService.ObserveCanExecute
Parameter | Type | Description |
|---|---|---|
|
| The action identifier. |
IHotKeyInfo
Provides a read-only description of a hot key action.
Property | Type | Description |
|---|---|---|
|
| Unique identifier of the action. |
|
| Display name. |
|
| Human-readable description. |
|
| Icon associated with the action. |
|
| Default gesture used when not overridden. |
IHotKeyAction
Defines an executable hot key action. Extends IHotKeyInfo.
Method | Return Type | Description |
|---|---|---|
|
| Whether the action can run for the given context. |
|
| Runs the action against the given context. |
IHotKeyAction.CanExecute
Parameter | Type | Description |
|---|---|---|
|
| The view model context. |
IHotKeyAction.Execute
Parameter | Type | Description |
|---|---|---|
|
| The view model context. |
|
| A token that cancels the operation. |