|
-
May 13th, 2021, 08:07 AM
#1
Thread Starter
New Member
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.
-
May 13th, 2021, 08:45 AM
#2
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.
-
May 13th, 2021, 10:33 AM
#3
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
 
-
May 13th, 2021, 11:09 AM
#4
Thread Starter
New Member
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.
-
May 13th, 2021, 11:11 AM
#5
Thread Starter
New Member
Re: Simple But Professional Visual Basic Auto Typer
I will keep that in mind, shaggy. thank you
-
May 13th, 2021, 11:37 AM
#6
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|