|
-
Oct 14th, 2004, 03:39 AM
#1
Thread Starter
Lively Member
Autotyper
Hey everybody,
This is my first post here so I want to make it clean and simple.
I want to make a program, just a simple one for my own use, which simulates the typing of a sentance. I have a command button and a text box, and when the command button is pressed, it types the text in the text box and hits enter, and continues doing that over and over. Is there any easy way to do this?
Thanks for your help everybody.
Last edited by Zeka; Oct 14th, 2004 at 04:32 PM.
"Most cars on our roads have only one occupant, usually the driver."
- Carol Malia, BBC Anchorwoman
"I do not like this word "bomb." It is not a bomb. It is a device that is exploding."
- Jacques le Blanc, French ambassador on nuclear weapons
"Solutions are not the answer."
- Richard Nixon, former U.S. President
-
Oct 14th, 2004, 04:00 AM
#2
What do you mean by "typing".
As I undersand you a textbox (in which you input/type a sentence) and you have a commandButton (which will "TYPE" the sentence for the textbox). The question is where do you want to "TYPE" that sentece, onto a label , into a document, on the screen, do you want to see it coming character by character?
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Oct 14th, 2004, 04:07 AM
#3
Thread Starter
Lively Member
I just want to simulate the different keypresses in the keypress.
If the typed sentance was "Cats hats" then the "c" would be simulated, then the "a", then the "t" etc.
So say if you opened notepad, the sentance would be typed in, then enter would be automatically pressed at the end of each sentance.
"Most cars on our roads have only one occupant, usually the driver."
- Carol Malia, BBC Anchorwoman
"I do not like this word "bomb." It is not a bomb. It is a device that is exploding."
- Jacques le Blanc, French ambassador on nuclear weapons
"Solutions are not the answer."
- Richard Nixon, former U.S. President
-
Oct 14th, 2004, 06:09 AM
#4
Sorry, but I don't get it.
What do you want to simulate?
If you put into the textbox "Cats hats" (you have to use the keypad and "punch" in C,a,t,s,space, h, a,t,s.). Then the textbox will display this sentence. So what do you want to program to do on the Command_Click event?
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Oct 14th, 2004, 08:46 AM
#5
Lively Member
You could make it look like something is being typed into your own textbox by adding a timer and putting in some code like this.
VB Code:
Const myString = "Check out my band's site at walterwalker.com"
Sub Command1_Click()
Timer1.enabled = True
End Sub
Sub Timer1_Timer()
Static X as Integer
X = X + 1
If X <= len(myString) Then
Text1 = left(myString, x)
Else
Timer1.Enabled = False
End If
End Sub
Of else you can actually send the text to your program or whatever other program has the focus at run time.
VB Code:
Const myString = "Walter Walter Rocks!"
Sub Command1_Click()
Timer1.enabled = True
End Sub
Sub Timer1_Timer()
Static X as Integer
X = X + 1
If X <= len(myString) Then
Sendkeys Mid(myString, 1, 1), True
Else
Timer1.Enabled = False
End If
End Sub
-
Oct 14th, 2004, 09:26 AM
#6
Hyperactive Member
Or if he doesn't want to put a timer on the form:
VB Code:
Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Sub Command1_Click()
Text1.SetFocus
SendKeys "C"
DoEvents
Sleep 100
SendKeys "a"
DoEvents
Sleep 100
SendKeys "t"
DoEvents
Sleep 100
SendKeys "s"
DoEvents
Sleep 100
SendKeys " "
DoEvents
Sleep 100
SendKeys "H"
DoEvents
Sleep 100
SendKeys "a"
DoEvents
Sleep 100
SendKeys "t"
DoEvents
Sleep 100
SendKeys "s"
End Sub
Of course this method turned out hellishly long, but it is another way of doing things 
Disiance
-
Oct 14th, 2004, 09:32 AM
#7
Hyperactive Member
Felt my above was much to long, so here's a better compilation:
VB Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Command1_Click()
TypeText "Cats Hats", Text1
End Sub
Sub TypeText(toType As String, Destination As TextBox)
Destination.SetFocus
Dim i As Integer
For i = 1 To Len(toType)
SendKeys Mid(toType, i, 1)
DoEvents
Sleep 100
Next i
SendKeys "{ENTER}" 'Could be replaced with SendKeys "~"
End Sub
And this will take any amount of characters up to 32,767, limited because of the 'i' variable being an integer.
Disiance
-
Oct 14th, 2004, 03:40 PM
#8
Thread Starter
Lively Member
Thanks alot you guys!
"Most cars on our roads have only one occupant, usually the driver."
- Carol Malia, BBC Anchorwoman
"I do not like this word "bomb." It is not a bomb. It is a device that is exploding."
- Jacques le Blanc, French ambassador on nuclear weapons
"Solutions are not the answer."
- Richard Nixon, former U.S. President
-
Oct 14th, 2004, 04:33 PM
#9
Thread Starter
Lively Member
There is one problem. Once the form is closed, it continues typing. Is there any function I can use to stop it?
Thanks
"Most cars on our roads have only one occupant, usually the driver."
- Carol Malia, BBC Anchorwoman
"I do not like this word "bomb." It is not a bomb. It is a device that is exploding."
- Jacques le Blanc, French ambassador on nuclear weapons
"Solutions are not the answer."
- Richard Nixon, former U.S. President
-
Oct 14th, 2004, 04:42 PM
#10
Zeka, Welcome to the Forum 
Which on of the methods above are you using?
-
Oct 15th, 2004, 12:36 AM
#11
Thread Starter
Lively Member
Oh yeah, forgot to mention. I found the example Disiance posted works best.
VB Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Command1_Click()
TypeText "Cats Hats", Text1
End Sub
Sub TypeText(toType As String, Destination As TextBox)
Destination.SetFocus
Dim i As Integer
For i = 1 To Len(toType)
SendKeys Mid(toType, i, 1)
DoEvents
Sleep 100
Next i
SendKeys "{ENTER}" 'Could be replaced with SendKeys "~"
End Sub
"Most cars on our roads have only one occupant, usually the driver."
- Carol Malia, BBC Anchorwoman
"I do not like this word "bomb." It is not a bomb. It is a device that is exploding."
- Jacques le Blanc, French ambassador on nuclear weapons
"Solutions are not the answer."
- Richard Nixon, former U.S. President
-
Oct 15th, 2004, 01:01 AM
#12
put this in the main form_unload:
Code:
Dim Frm As Form
For Each Frm In Forms
Unload frm
Next
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
|