VB.NET中的关键组合

时间:2016-08-25 04:48:52

标签: vb.net

任何人都可以帮我在VB.NET中读取多个击键。例如,我想阅读Control + P + H组合键。我尝试了类似下面的代码,但没有用... 在形式Keydown

if e.control=true and e.keycode=keys.P and e.keycode=keys.H then
end if

1 个答案:

答案 0 :(得分:3)

在看完你的帖子之后,从我能理解的内容来看,这样的事情就可以了。

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

如果您有任何疑问,请告诉我,我会尽力回答,但这样可以让您顺利完成:)