Click here to Skip to main content
15,843,865 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good morning, there's one implement I want in my project which is an autotyper. Similar to the way KeyPass AutoTyper works, but less advanced disregarding sequences.

I'm trying to code an autotyper which when I press the start button it will simply just await for a text field(like SendKeys.Send), and it will send each character in the string to a text field in order and will stop the autotyper automatically once the entire string was sent.

I tried various methods including using for each character in a string sendkeys, but it always doesn't work properly. For an example, I run the project and go to the Auto Type Form, which is an external form using autotypeform.show, it also has topmost on it so when i go to a browser it's still visible, once you the click start button it starts the autotyper timer in main form, once i go to a text field(google.com search bar for an example) it will sendkeys but not the entire string or it will occasionally skip a character. Can someone please help?

NOTE: There is also a registered hotkey (ALT + T) to start the timer, and the timer interval is 1000, I tried 1-2000.

VB
Private Sub autoTyper_Tick(sender As Object, e As EventArgs) Handles autoTyper.Tick
       
        Dim Text As String = autoTypeForm.setText.Text

        'ATTEMPT 1
        'For i = 0 To autoTypeForm.setText.Text.Length - 1

        'SendKeys.Send(Text(i))

        'Next

        'ATTEMPT 2
        'Dim Counter As Integer

        'For Counter = 1 To Len(Text)

        'SendKeys.Send(Mid(Text, Counter, 1))

        'Next

        'ATTEMPT 3
        For Each c As Char In Text

            SendKeys.Send(c)

        Next

        autoTyper.Stop()

  End If


What I have tried:

I tried the following 3 methods including others.
Posted
Updated 13-May-21 10:11am
Comments
Gerry Schmitz 13-May-21 12:48pm    
If you want to "send keys" to a particular control, that control needs to have "focus".
Mycroft Holmes 13-May-21 19:30pm    
Is it possible to detect the window that had the focus BEFORE he clicked the start button? Oh and then he needs to identify the selected object (textbox) in that window- nasty
Gerry Schmitz 14-May-21 14:59pm    
I use "GotFocus" and "LostFocus" (and my own "can focus") on my controls when I do "focus tracking" ... but the firing order isn't always obvious or intuitive (requires testing).

1 solution

If you're sending keys to another window in your app, what you're doing isn't going to work very well because your SendKeys loop is blocking the UI thread while sending the keys, preventing the control with the focus from getting any messages to update with new content and repaint.
 
Share this answer
 
v2

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