我正在创建一个快捷键来打开某个表单,我有KeyPreview = true
而且我正在使用这段代码而且效果很好!
#Region "Shortcuts"
Private Sub frmQueuing_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If (e.KeyCode = Keys.A AndAlso e.Modifiers = Keys.Control) Then
frmMain.show()
End If
End Sub
#End Region
但是我尝试通过添加Alt和Shift来扩展该代码,现在它无法正常工作。我不知道为什么。
#Region "Shortcuts"
Private Sub frmQueuing_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If (e.KeyCode = Keys.A AndAlso e.KeyCode = Keys.Shift AndAlso e.KeyCode = Keys.Alt AndAlso e.Modifiers = Keys.Control) Then
frmMain.show()
End If
End Sub
#End Region
答案 0 :(得分:1)
尝试使用
#Region "Shortcuts"
Private Sub frmQueuing_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If (e.Control AndAlso e.Shift AndAlso e.Alt AndAlso e.KeyCode = Keys.A) Then
frmMain.show()
End If
End Sub
#End Region
这些链接可帮助您了解time和KeyEventArgs.KeyCode Property
之间的差异答案 1 :(得分:1)
您可以使用:
If e.KeyCode = Keys.A And Control.ModifierKeys = (Keys.Control + Keys.Shift + Keys.Alt) Then