does anyone know how I would go about creating a program that would type a message into a text box??(Note: this text box would be in another app. and I would like it to type like someone was really doing it) Thanks for your help!
Printable View
does anyone know how I would go about creating a program that would type a message into a text box??(Note: this text box would be in another app. and I would like it to type like someone was really doing it) Thanks for your help!
SendKeys
Do a search on the forum for senkeys
i did and i found some usefull info, but im still not sure how to implement the timer to pause between each keystroke... can you help??
Sleep
Do a search on the forum for sleep
Man, don't go thinking to hard LoL.Quote:
Originally posted by Lightning
Sleep
Do a search on the forum for sleep
SendKeys
Do a search on the forum for senkeys
Sorry it is still early, and I didn't sleep enough :o . But I still want to help hem, so SORRY for the short and lazy answers.
can you tell me why this snippet wont work??
Private Sub Command1_Click()
Timer1.Interval = 2000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
SendKeys "^R"
End Sub
What doesn't work, the timer, or the sendkeys?
The timer should work or is it the sendkeys part that doesn't work?
Look at this example:
VB Code:
Dim CalcVal, I CalcVal = Shell("calc.exe", 1) ' Run Calculator. AppActivate CalcVal ' Activate the Calculator. For I = 1 To 10 ' Set up counting loop. SendKeys I & "{+}", True ' Send keystrokes to Calculator Next I ' to add each value of I. SendKeys "=", True ' Get grand total. msgbox "Sum visable in calculator " SendKeys "%{F4}", True ' Send ALT+F4 to close Calculator.
It might get you "on the road"
Nah, no need to be sorry I just got a laugh out of it was all, had to remark. :D
Now I'm awak, my posts look really stupid, this morning they look handy...
Sendkeys is not too reliable. If you have the time and patience try
using APIs which is a more reliable way. Sendkeys depends upon
the application being the active window and if it changes during
execution, only part of the data will be entered.
Some APIs to use...
FindWindow - Finds the handle to the main programs window.
FindWindowEx - Finds the child window ex. textbox control.
SendMessage - Read/Write data to the textbox.
:)
Lightning, with the sleep command, would i be able to pause for .5sec between each keystroke, so that it looks like im typing??? If so, could u show me what it would look like??
RobDog, i would use apis if i could, but i dont know how to do those... sorry!
hello??? can any1 help me??
VB Code:
'Module! Public Declare Function GetTickCount Lib "kernel32" () As Long Sub Pause(Length As Long) Dim OldTime As Long OldTime = GetTickCount Do DoEvents If GetTickCount >= OldTime + Length Then Exit Do Loop End Sub 'Form Pause (1000)'1 second Pause (50) is probably good for typing 'Typer Function Add(strMessage As String) As String Dim i As Integer For i = 1 To Len(strMessage) Label1.Caption = Label1.Caption & Mid$(strMessage, i, 1) Pause (100) Next End Function 'caller Add (Text1.Text)
*CHEERS*
alacritous
thx alot alacritous, but when i put it into vb, it didn't work, can u help me??
*welcome*...
hmm...what happens?? error?? or what? be specific and I might just be able to help you!
EDIT: I just noticed you browsing forums...if you have aim msg me at alacritous8 or msn messenger at [email protected], so it will be easier to talk.
*cheers*
alacritous
just as a reference, if u know what a aplhasmart is, i want the program to act just like one(when u syncronize it with the computer)
if u don't know what an alphasmart does, it emulates a keyboard, and types in the words when you hook it up to a computer(through the keyboard connector). Does anyone know how to do this??
Alacritiouses code should work, lemme just make it so you can copy and paste it into your form.
VB Code:
'Module! Public Declare Function GetTickCount Lib "kernel32" () As Long private Sub Pause(Length As Long) Dim OldTime As Long OldTime = GetTickCount Do DoEvents If GetTickCount >= OldTime + Length Then Exit Do Loop End Sub private sub form_activate dim strmessage as string strmessage = "this is a test" Dim i As Integer For i = 1 To Len(strMessage) Label1.Caption = Label1.Caption & Mid$(strMessage, i, 1) Pause (100) Next end sub
that should work, just make sure to put a label on the form before you run it.
knowledge, thx alot! However, when i put the code into my form, it says compile error and says constants, fixed length strings, user defined types, and declare statements are not allowed as public members of object modules.
now, i may be doing something wrong. all i did was copy the code directly into my form under general. Am I supposed to put it somewhere else?? Thx!
it says..VB Code:
'Module code
ok, so, whats up with the error???
if this doesn't work..screw it...you got to readVB Code:
'Module! Public Declare Function GetTickCount Lib "kernel32" () As Long private Sub Pause(Length As Long) Dim OldTime As Long OldTime = GetTickCount Do DoEvents If GetTickCount >= OldTime + Length Then Exit Do Loop End Sub 'Form private sub form_activate dim strmessage as string strmessage = "this is a test" Dim i As Integer For i = 1 To Len(strMessage) Label1.Caption = Label1.Caption & Mid$(strMessage, i, 1) Pause (100) Next end sub
Hmm.. okay, looks like somebody missed an important part of your education in VB. Modules are a place to put code that is accessible by all of the project. Goto the project menu, the third from 'file', and select 'add module'. In there, put the code commented as module, the rest of the code (commented form), goes into the form. Modules are used to organize code, and allow you to do *some* things to make it easier to call functions.
thx alot knowledge!!!! that fixed everything. i knew i was doin something wrong....
now if i can only implement the sendkeys stuff in there....
I've changed it to :
VB Code:
Private Sub Command1_Click() Dim strmessage As String strmessage = Text1.Text Dim i As Integer For i = 1 To Len(strmessage) Label1.Caption = Label1.Caption & Mid$(strmessage, i, 1) Pause (100) Next End Sub
but how would I change it to use sendkeys?? could i just do:
or would i have to change more??VB Code:
Private Sub Command1_Click() Dim strmessage As String strmessage = Text1.Text Dim i As Integer For i = 1 To Len(strmessage) SendKeys = "Mid$(strmessage, i, 1)" Pause (100) Next End Sub
hmm, i tryed that, and it seems that the sendkeys command is unable to do such a command.... do I have to manipulate the code another way, or is there another command??
needs to be changed toVB Code:
SendKeys = "Mid$(strmessage, i, 1)"
VB Code:
SendKeys Mid$(strmessage, i, 1)
sorry, one last thing!!!
how do i stop this thing??????? It doesn't stop until its done, and I would like to be able to stop it from typing.....
Hello,
VB Code:
Dim Stop as Boolean Private Sub Command1_Click() Dim strmessage As String strmessage = Text1.Text Dim i As Integer For i = 1 To Len(strmessage) If Stop = True Then Stop = False Exit Sub End If SendKeys Mid$(strmessage, i, 1) Pause (100) Next End Sub Private Sub Command1_Click() Stop = True End Sub
I havn't tested it, but it should work...
*CHEERS*
alacritous
hmmm, doesn't work.....
vb won't let me use stop as the name of the variable, so I changed it, but it still doesn't work......
VB Code:
Dim CANCELIT As Boolean Private Sub Command1_Click() Label1.Caption = "" Add (Text1.Text) End Sub Private Sub Command2_Click() CANCELIT = True End Sub Function Add(strMessage As String) As String Dim i As Integer For i = 1 To Len(strMessage) If CANCELIT = True Then CANCELIT = False Exit Function End If Sendkeys Mid$(strMessage, i, 1) Pause (100) Next End Function
Command1, Command2, Label1, Text1
Works for me...
*CHEERS*
alacritous
here the code i have.... I don't know how I would add ur code to it though.... how would i do it.. as you can see, i tried to do it, though unsuccessfully....
VB Code:
Dim CANCELIT As Boolean Private Sub Pause(Length As Long) Dim OldTime As Long OldTime = GetTickCount Do DoEvents If GetTickCount >= OldTime + Length Then Exit Do Loop End Sub Private Sub Command1_Click() Dim Acc As Integer If IsNumeric(Text2.Text) Then Acc = Text2.Text Else MsgBox "Please enter a numeric value" End If Pause (1000) Function Add(strMessage As String) As String strMessage = Text1.Text Dim i As Integer For i = 1 To Len(strMessage) If CANCELIT = True Then CANCELIT = False Exit Function End If SendKeys Mid$(strMessage, i, 1) Pause (Acc) Next End Function End Sub Private Sub Command2_Click() Text1.Text = "" End Sub Private Sub Command3_Click() CANCELIT = True End Sub
Hello,
Bad. News. You need to work on your functions, subs, oraganization, placings, and other stuff before you continue to do difficult, or rather simple functions. You don't put a function in a sub... I'll help you this one more post...I don't really have time. And I'm very sorry if I'm mean, but someone told me the same thing. But basically, I can't even read your code...
I'll post the code, correctly... if you change it and mess up...
*CHEERS*
alacritous