我试图在VB.net应用程序中捕获两个按键,对于这个示例CTRL B,下面的代码不起作用,但它对于单个键.我已经尝试将keypreview设置为true,但这没有任何效果.
Private Sub main_KeyDown(ByVal sender As Object,ByVal e As System.Windows.Forms.KeyEventArgs) Handles mybase.KeyDown If e.KeyCode = Keys.ControlKey And e.KeyCode = Keys.B Then MsgBox("CTRL + B Pressed !") End If End Sub End Class
谢谢
控制键是一个修饰符键.此代码测试Ctrl B
原文链接:https://www.f2er.com/vb/255096.htmle.KeyCode = Keys.B AndAlso e.Modifiers = Keys.Control
键代码为B,但修饰符为Ctrl.
您的代码段,更新:
Private Sub main_KeyDown(ByVal sender As Object,ByVal e As System.Windows.Forms.KeyEventArgs) Handles mybase.KeyDown If (e.KeyCode = Keys.B AndAlso e.Modifiers = Keys.Control) Then MsgBox("CTRL + B Pressed !") End If End Sub