Click here to Skip to main content
15,881,712 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to develop a keystroke macro program using which will record keystrokes like keydown and keyup events and then play it anywhere while the main program is running in the background. As of now I have successfully captured the keystrokes and stored those strokes. But the problem which I m facing, is at the time of playing those stored keystrokes. I can't fire the KeyDown and KeyUp events from any external program. I have tried SendKeys method as well but it cannot differentiate between KeyDown and KeyUp separately. Help in this scenario will highly be appreciated.

The KeyDown event which is accessible in parent program only.

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        'bla bla bla
End Sub

What I have tried:

Use of SendKeys but it cannot distinguish between KeyDown and KeyUp

Private Function AutoSendKey(ByVal keystroke As String, ByVal delay As Integer)     
        My.Computer.Keyboard.SendKeys(keystroke, True)
    End Function

I need an approach to trigger KeyDown and KeyUp events from external applications. Thanks in advance
Updated 25-Dec-21 2:12am

1 solution

Sounds like you are looking for something like SendInput

SendInput function (winuser.h) - Win32 apps | Microsoft Docs[^]

SendInput allows you to control keyboard events in detail. You can use it by the help of pInvoke. There are lot of example available.

I hope it helps.
Share this answer
Maciej Los 3-Jan-22 15:24pm    
0x01AA 3-Jan-22 15:29pm    
Thank you very much Maciej

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900