KeyboardWatcher ClassDW.WPFToolkit Documentation
Brings possibilities to listen for keyboard events even the current application has not the focus. Its the so called System Keyboard Hooks.
Inheritance Hierarchy

SystemObject
  DW.WPFToolkit.HelpersKeyboardWatcher

Namespace: DW.WPFToolkit.Helpers
Assembly: DW.WPFToolkit (in DW.WPFToolkit.dll) Version: 5.6.0.0
Syntax

C#
public class KeyboardWatcher : IDisposable

The KeyboardWatcher type exposes the following members.

Constructors

  NameDescription
Public methodKeyboardWatcher
Initializes a new instance of the KeyboardWatcher class.
Top
Methods

  NameDescription
Public methodAddCallback(ActionKeyStateChangedArgs)
Registers a callback which got called no matter which keys were pressed or released.
Public methodAddCallback(IEnumerableKey, ActionKeyStateChangedArgs)
Registers a callback which got called if one of the given key changed their state.
Public methodAddCallback(Key, ActionKeyStateChangedArgs)
Registers a callback which got called if the specific key changed its state.
Public methodAddCallback(KeyState, ActionKeyStateChangedArgs)
Registers a callback which got called no matter which keys came into the specific state.
Public methodAddCallback(IEnumerableKeyState, ActionKeyStateChangedArgs)
Registers a callback which got called no matter which keys came into the specific states.
Public methodAddCallback(IEnumerableKey, KeyState, ActionKeyStateChangedArgs)
Registers a callback which got called if one of the given keys changed their state to the specific one.
Public methodAddCallback(IEnumerableKey, IEnumerableKeyState, ActionKeyStateChangedArgs)
Registers a callback which got called if one of the given keys changed their state to one of the given states.
Public methodAddCallback(Key, KeyState, ActionKeyStateChangedArgs)
Registers a callback which got called if the specific key changed its state to the given one.
Public methodAddCallback(Key, IEnumerableKeyState, ActionKeyStateChangedArgs)
Registers a callback which got called if the specific key changed its state to one of the given states.
Public methodBeginWatch
Begin watching for system wide keyboard events.
Public methodClearCallbacks
Removes all known callbacks.
Public methodDispose
Public methodRemoveCallback
Removes a registered callbacks by the token.
Public methodStopWatch
Stop watching for system wide keyboard events.
Top
Events

  NameDescription
Public eventKeyStateChanged
Occurs when the user pressed or released key.
Top
Examples

C#
public class MainViewModel
{
    public MainViewModel()
    {
        var watcher = new KeyboardWatcher();
        watcher.AddCallback(KeyPressed);

        watcher.BeginWatch();
    }

    private void KeyPressed(KeyStateChangedArgs e)
    {
        if (e.Key == Key.F10 && e.State == KeyState.Pressed)
        {
            // User Pressed the F10 key
        }
    }
}
See Also

Reference