Reputation: 36
Can any one help me to read multiple key strokes in VB.NET.for Example, I want to read Control+P+H key combinations.I tried something like the code below but didn't work... In form Keydown
if e.control=true and e.keycode=keys.P and e.keycode=keys.H then
end if
Upvotes: 0
Views: 1509
Reputation: 996
Ok after reading your post and from what I can understand, something like this should do the trick.
Public Class Form1
Dim keyCombo As New List(Of Keys)({Keys.ControlKey, Keys.H, Keys.P})
Dim currentKeys As New List(Of Keys)
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
currentKeys.Add(e.KeyCode)
If currentKeys.Intersect(keyCombo).Count = keyCombo.Count Then
MessageBox.Show("CTRL + H + P Has Been Pressed....")
currentKeys.Clear()
End If
End Sub
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
currentKeys.Remove(e.KeyCode)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True
End Sub
End Class
If you have any questions, let me know and I will try my best to answer them, however this should get you well and truly on your way :)
Upvotes: 3