Results 1 to 6 of 6

Thread: Simple But Professional Visual Basic Auto Typer

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2021
    Posts
    6

    Question Simple But Professional Visual Basic Auto Typer

    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.

    Code:
    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
    Last edited by shatayviamcduffie; May 13th, 2021 at 08:13 AM.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    Re: Simple But Professional Visual Basic Auto Typer

    While don't have an answer to your question I do have a few coding tips:
    1. I see no reason to use the Mid function for single characters. Why not use the .Chars method which is available for all strings?
    2. Some of your For loops have the iterator variable declared on a separate statement. Why?
    3. If you need to iterate through all characters in a string from start to end why not always use a For Each loop?
    4. Also consider using Array.Foreach instead of a For loop.
    5. Keep in mind there also is Linq which can be used when dealing with arrays and collections.

    Also, as to sending keys you might want to use API functions: https://docs.microsoft.com/en-us/win...er-sendmessage.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Simple But Professional Visual Basic Auto Typer

    Don't use Google for testing. If you do, you see what you are sending, but you can't see the other side. For testing, create your own target such that you can see both sides.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2021
    Posts
    6

    Re: Simple But Professional Visual Basic Auto Typer

    1. to be honest i was just using google "Loop For Each Character In String Visual Basic" & just copying & pasting any code I seen.
    2. ^
    3. I did use a for each loop for last attempt.
    4. I will keep in mind.
    5. I will keep in mind.

    6. Thanks for the tip, will do.

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2021
    Posts
    6

    Re: Simple But Professional Visual Basic Auto Typer

    I will keep that in mind, shaggy. thank you

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Simple But Professional Visual Basic Auto Typer

    Why is it in a timer, and why aren't you stopping the time as the first thing you do? That might also be part of your issue. Typically if you're going to stop a timer inside of the Tick event, that should be the FIRST thing you do, other wise that even could fire off again, while you're still inside of it, causing unpredictable results. Also, have you tried sending the whole string, rather than just one character at a time?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width