I am trying to write a simple desktop application to capture user input and write it to a text file. I have figured out how to capture the mouse mouse movement and mouse clicks. I am writing this information to a text file. Then I am using the application to recreate the actions that were performed with the input devices. Basically I am trying to write my own macro recorder.
I’m not sure what I am doing wrong when it comes to capturing keyboard input. I am using the following code, but it is not being executed when I type with my keyboard. Therefore, it is not writing the keyboard input to the text file. What am I overlooking?
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
Try
' Add key down event to recorded actions
Dim key As Keys = e.KeyCode
recordedActions.Add(String.Format("KeyDown,{0}", key))
Catch ex As Exception
MessageBox.Show("Error capturing key down: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
Try
' Add key up event to recorded actions
Dim key As Keys = e.KeyCode
recordedActions.Add(String.Format("KeyUp,{0}", key))
Catch ex As Exception
MessageBox.Show("Error capturing key up: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub