vb.neteventscallkeyboard-eventskeyevent

How to call a Sub with KeyEventArgs from another Sub


I have two subs

Private Sub kbHook_KeyDown(ByVal Key As System.Windows.Forms.Keys) Handles KeyHook.KeyDown

and

Private Sub Form1_KeyPressCaps(ByVal key As Object, e As KeyEventArgs) Handles Me.KeyDown

    If e.KeyCode = Keys.CapsLock Then
        If keyStCL = True Then

            checkbutton_caps.Checked = False
            checkbutton_caps.Image = My.Resources.Resource1.btn_ico_caps_off
            'Image.FromFile("resources\btn_ico_caps_off.png")
            keyStCL = False

        ElseIf keyStCL = False Then
            checkbutton_caps.Checked = True
            checkbutton_caps.Image = My.Resources.Resource1.btn_ico_caps_on
            'Image.FromFile("resources\btn_ico_caps_on.png")
            keyStCL = True

        End If
    End If
End Sub

I want to call Form1_KeyPressCaps from kbHook_KeyDown. How do I do it.
I tried this:

Private Sub kbHook_KeyDown(ByVal Key As System.Windows.Forms.Keys) Handles KeyHook.KeyDown
    Call Form1_KeyPressCaps(Key, New KeyEventArgs)
End Sub

But its not working. I am getting an error:

Argument not specified for parameter 'keyData' of 'Public Sub New(keyData As System.Windows.Forms.Keys)'.


Solution

  • Private Sub kbHook_KeyDown(ByVal Key As System.Windows.Forms.Keys) Handles KeyHook.KeyDown
        Call Form1_KeyPressCaps(Key, New KeyEventArgs(Key))
    End Sub