Q:

VB GetAsyncKeyState, combobox selected keys

I'm trying to do an action, when specific keys, selected by the user, are pressed.. but I don't know how to do It.
Is there any easiest way to to this:
If ComboBox1.SelectedItem = "F8"
    If GetAsyncKeyState(Keys.F8) Then
        'something
    End If
ElseIf ComboBox1.SelectedItem = "F9"
    If GetAsyncKeyState(Keys.F9) Then
        'something
    End If
ElseIf ComboBox1.SelectedItem = "F10"
    If GetAsyncKeyState(Keys.F10) Then
        'something
    End If
End If
'and other more..

I tried
Dim asd as String
asd = ComboBox1.Text
If ComboBox1.Text Then
    If GetAsyncKeyState(Keys.kj) Then
        'something
    End If
End If

A:

One simple way is to put everything in a Dictionary, using it you can check the specified keyboard key by the Dictionary key.
First, declare this at class level (outside any sub or function):
Dim Hotkeys As New Dictionary(Of String, Keys) From { _
    {"F8", Keys.F8}, _
    {"F9", Keys.F9}, _
    {"F10", Keys.F10} _
}

Then when you are going to check if the specified key was pressed you'd just do:
If GetAsyncKeyState(Hotkeys(ComboBox1.SelectedItem.ToString())) Then
    'Some code here
End If

To add more keys you just keep adding rows to the Dictionary.
{"<key alias>", Keys.<key value>}, _

<key alias> (without the <> brackets) must be exactly the same as the respective item in the ComboBox.
And a final note: every row should end with }, _ except for the last one, which includes no comma } _.
Hope this helps!

