I want to trigger code were if i press ctrl + G on the keyboard, it will trigger my code! Thing is, it wont work. If i hit the letter u or g on its own, my else triggers grand! What am i doing wrong?
My question is different than others because im trying to get a keypress event off of a webbrowser component. So i have to make do with what i got and make a keypress event using document.body.keydown
adding that into a eventhandler
My code:
Private Sub AdsDisplayer_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles AdsDisplayer.DocumentCompleted
AddHandler AdsDisplayer.Document.Body.KeyDown, AddressOf AdsDisplayer_KeyDown
End Sub
Private Sub AdsDisplayer_KeyDown(ByVal sender As Object, ByVal e As HtmlElementEventArgs)
If e.CtrlKeyPressed And Chr(e.KeyPressedCode) = "G" Then
'CTRL+G was pressed.
MsgBox("CTRL + " & Chr(e.KeyPressedCode))
Else
'SomeKey was pressed without any modifier keys.
MsgBox(Chr(e.KeyPressedCode))
End If
End Sub
EDIT
What i tried from below comments and not working:
If (e.KeyPressedCode And Not Keys.Modifiers) = Keys.G AndAlso e.CtrlKeyPressed = Keys.ControlKey Then
MsgBox("Ctrl + G")
End If