How to detect if any key is pressed

c#, c#-4.0, wpf

Solution

public static IEnumerable<Key> KeysDown()
{
    foreach (Key key in Enum.GetValues(typeof(Key)))
    {
        if (Keyboard.IsKeyDown(key))
            yield return key;
    }
}

you could then do:

if(KeysDown().Any()) //...

Problem

How can I detect if any keyboard key is currently being pressed? I'm not interested in what the key is, I just want to know if any key is still pressed down. ``` if (Keyboard.IsKeyDown(Key.ANYKEY??) { } ```

Original source

Related problems