As far as your new question (from the comment left on my last answer), the user should always press ctrl, shift, or alt first. That's the way it works everywhere.
If I am in Word, highlight some text, and hold "c" and then hit ctrl to initiate a copy event, it won't work. What will happen is that the highlighted text will first become the letter "c", then "c" will be repeated until control is pressed. At that point, no text will be highlighted, so nothing will be copied.
It should always be assumed that ctrl, alt, and shift should be pressed first.
If, however, you are pressing Ctrl first and then F1 and you are getting duplicate messages, the problem is in your code. Let's say, you have written
If e.KeyCode = Keys.F1 Then
MessageBox.Show("F1")
End If
If e.KeyCode = Keys.F1 and e.Control Then
MessageBox.Show("F1 + Ctrl")
End If
you will get two messages. Do you see why?
Also, just a few little tips since you appear to be new to .Net.
First,
MsgBox
shouldn't be used anymore. That's an old VB6 structure. You should be using
MessageBox.Show("some text")
.
Secondly, you don't need to test boolean values against true or false. That is just added steps the application will have to take.
If e.Control Then
If e.Control = True
The difference is that
e.Control = True
has to first test that condition and then check whether that test returned true or false.
Finally, if you are testing a lot of possibilities for
e.KeyCode
, you would be better off using the
Select Case
structure. It would look like:
Dim output as String = ""
Select Case e.KeyCode
Case Keys.F1
output = "F1"
Case Keys.F2
output = "F2"
End Select
If e.Control Then
output = output & "+Ctrl"
End If
MessageBox.Show(output)