How can I find the state of NumLock, CapsLock or ScrollLock in WPF?

Full article

If you're writing a WPF application and need to find the state of the Num Lock, Caps Lock, or Scroll Lock keys, you can use the Keyboard.IsToggled method (introduced in .NET 3.0):

var isNumLockToggled = Keyboard.IsKeyToggled(Key.NumLock);
var isCapsLockToggled = Keyboard.IsKeyToggled(Key.CapsLock);
var isScrollLockToggled = Keyboard.IsKeyToggled(Key.Scroll);

Add this using directive to the top of your class, if it's not already there:

using System.Windows.Input;

Internally, the IsToggled() method checks to see whether or not a KeyStates.Toggled flag is set for the specified key.

public enum KeyStates : byte
    None = (byte) 0,
    Down = (byte) 1,
    Toggled = (byte) 2,


Grant Winney

I write when I've got something to share - a personal project, a solution to a difficult problem, or just an idea. We learn by doing and sharing. We've all got something to contribute.

Comments / Reactions