I'am working on creating a shortcut keys to open a certain form, I have KeyPreview = true
and I am using this code and it works great!
#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
However I tried to expand that code by adding Alt and Shift, it is not working now. I don't know why.
#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
try using
#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
these links will help you to understand differences between KeyEventArgs.KeyCode Property and KeyEventArgs.Alt Property
您可以使用:
If e.KeyCode = Keys.A And Control.ModifierKeys = (Keys.Control + Keys.Shift + Keys.Alt) Then
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.