Search code examples
c#hotkeys

c# & GetAsyncKeyState() - How to check all keys?


This code

for (int i = 0; i < 256; i++)
{
    if (GetAsyncKeyState(i) == -32767)
    {
        MessageBox.Show(i.ToString());
    }
}

excludes i.e. function keys (F1, F2, and so on) or numpad keys.

What do I need to do, to make this code work for all keys?

Thanks in advance.


Solution

  • For further reference:

    You should use Keys enum. You can use Foreach on Enum.

    Keys enum is an integer, so you can reference it by it's number later on.