Skip to content

KeyboardShortcuts.KeyRegistry

JaykeBird edited this page Feb 21, 2023 · 9 revisions

Back to home | Back to Reference | View raw text

KeyRegistry class

Description

A class to hold and handle keyboard shortcuts, and determine which shortcut to use based upon key presses.

Diagram

  flowchart LR
  classDef interfaceStyle stroke-dasharray: 5 5;
  classDef abstractStyle stroke-width:4px
  subgraph SolidShineUi.KeyboardShortcuts
  SolidShineUi.KeyboardShortcuts.KeyRegistry[[KeyRegistry]]
  end
Loading

Members

Properties

Public properties

Type Name Methods
IReadOnlyList<KeyboardShortcut> RegisteredShortcuts
A read-only list of all keyboard shortcuts registed in this registry. Use the RegisteryKeyShortcut and UnregisterKeyShortcut methods to add or remove shortcuts.
get

Methods

Public methods

Returns Name
(IKeyAction Item1, string Item2) GetActionForKey(...)
Get the IKeyAction associated with a certain keyboard shortcut.
IEnumerable<KeyboardShortcut> GetShortcutsForMethod(string methodId)
Get a list of keyboard shortcuts registered to a certain method.
void RegisterKeyShortcut(...)
Register a keyboard shortcut with the registry.
bool UnregisterKeyShortcut(...)
Unregister (remove) a shortcut from this registry.

Details

Summary

A class to hold and handle keyboard shortcuts, and determine which shortcut to use based upon key presses.

Constructors

KeyRegistry

public KeyRegistry()

Methods

RegisterKeyShortcut [1/2]

public void RegisterKeyShortcut(KeyboardShortcut kc)
Arguments
Type Name Description
KeyboardShortcut kc The keyboard shortcut to register.
Summary

Register a keyboard shortcut with the registry.

RegisterKeyShortcut [2/2]

public void RegisterKeyShortcut(KeyboardCombination combination, Key key, IKeyAction action)
Arguments
Type Name Description
KeyboardCombination combination The combination of modifier keys to press for this shortcut.
Key key The specific key that activates this keyboard shortcut.
IKeyAction action The action to perform when the keyboard shortcut is pressed.
Summary

Register a keyboard shortcut with the registry.

UnregisterKeyShortcut [1/2]

public bool UnregisterKeyShortcut(KeyboardShortcut ks)
Arguments
Type Name Description
KeyboardShortcut ks The keyboard shortcut to unregister.
Summary

Unregister (remove) a shortcut from this registry.

Remarks

This overload of this method looks for a specific keyboard shortcut instance that is currently in the registry. To remove based upon the keys being pressed, use the other overload instead ( KeyRegistry.UnregisterKeyShortcut(SolidShineUi.KeyboardShortcuts.KeyboardCombination,System.Windows.Input.Key) ).

Returns

Returns if the shortcut was able to be removed or not. Will return false if this registry does not contain this specific shortcut.

UnregisterKeyShortcut [2/2]

public bool UnregisterKeyShortcut(KeyboardCombination combination, Key key)
Arguments
Type Name Description
KeyboardCombination combination The combination of modifier keys to be pressed for this shortcut.
Key key The key to press to activate this shortcut.
Summary

Unregister (remove) a shortcut from this registry.

Returns

True if the shortcut was found and removed; false if there is no shortcut with this particular key and modifier key combination.

GetShortcutsForMethod

public IEnumerable<KeyboardShortcut> GetShortcutsForMethod(string methodId)
Arguments
Type Name Description
string methodId The name of the method. If you used RoutedEventKeyAction.CreateListFromMenu(SolidShineUi.Menu) to fill from a menu, the name will be the name of the MenuItem itself.
Summary

Get a list of keyboard shortcuts registered to a certain method.

Returns

GetActionForKey [1/2]

public (IKeyAction Item1, string Item2) GetActionForKey(KeyboardCombination combination, Key key)
Arguments
Type Name Description
KeyboardCombination combination The combination of modifier keys to have pressed for this shortcut.
Key key The key for this shortcut.
Summary

Get the IKeyAction associated with a certain keyboard shortcut.

Returns

A Tuple containing the IKeyAction associated with this shortcut, if there is one (null if there is not), and a friendly string that displays the keyboard combination to press (i.e. "Ctrl+Alt+V").

GetActionForKey [2/2]

public (IKeyAction Item1, string Item2) GetActionForKey(Key key, bool shift, bool alt, bool ctrl)
Arguments
Type Name Description
Key key The key for this shortcut.
bool shift Set if the Shift key is part of this shortcut.
bool alt Set if the Alt key is part of this shortcut.
bool ctrl Set if the Ctrl key is part of this shortcut.
Summary

Get the IKeyAction associated with a certain keyboard shortcut.

Returns

A Tuple containing the IKeyAction associated with this shortcut, if there is one (null if there is not), and a friendly string that displays the keyboard combination to press (i.e. "Ctrl+Alt+V").

Properties

RegisteredShortcuts

public IReadOnlyList<KeyboardShortcut> RegisteredShortcuts { get; }
Summary

A read-only list of all keyboard shortcuts registed in this registry. Use the RegisteryKeyShortcut and UnregisterKeyShortcut methods to add or remove shortcuts.

Events

ShortcutRegistered

public event KeyboardShortcutEventHandler ShortcutRegistered
Summary

Raised when a shortcut is added (registered) to this KeyRegistry.

ShortcutUnregistered

public event KeyboardShortcutEventHandler ShortcutUnregistered
Summary

Raised when a shortcut is removed (unregistered) from this KeyRegistry.

Delegates

KeyboardShortcutEventHandler

public delegate void KeyboardShortcutEventHandler(object sender, KeyboardShortcutEventArgs e)
Arguments
Type Name Description
object sender
KeyboardShortcutEventArgs e

Generated with ModularDoc

Clone this wiki locally