0

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.

Reese
  • 253
  • 5
  • 15
  • have you looked at [Keys enum](https://msdn.microsoft.com/en-us/library/system.windows.forms.keys(v=vs.110).aspx)? – Gabriel GM Sep 12 '16 at 02:33
  • @GabrielGM Yes, I did. But there are no values which I could use to save the key in an *.ini File. – Reese Sep 12 '16 at 06:06
  • Not quite sure I understand what you mean by an ini file.. Loop with a [foreach](http://stackoverflow.com/questions/105372/how-do-i-enumerate-an-enum)? – Gabriel GM Sep 12 '16 at 13:06
  • Yes, maybe I explained it badly. I want to customize the user's hotkeys within the program. I think, I can save the Key Codes of all Keys as integer into an ini file. To ask the user for a key I want to take a textbox. Within this textbox the user should be able to but any key. Normal keys like letters are not the problem, but how do I detect the F1 to F12 keys and how to save them into an ini file? Thanks in advance. – Reese Sep 12 '16 at 14:12
  • F1 to F12 are also represented by int in the enum (see http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/Keys.cs,c9ea55b52b93f5c4) – Gabriel GM Sep 12 '16 at 14:43

1 Answers1

1

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.

Community
  • 1
  • 1
Gabriel GM
  • 6,391
  • 2
  • 31
  • 34