Results 1 to 33 of 33

Thread: Program That Types[ ALMOST RESOLVED!]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83

    Program That Types[ ALMOST RESOLVED!]

    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!
    Last edited by poopyman67; Aug 30th, 2003 at 11:46 PM.

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611
    SendKeys

    Do a search on the forum for senkeys

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83
    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??

  4. #4
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611
    Sleep

    Do a search on the forum for sleep

  5. #5
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068
    Originally posted by Lightning
    Sleep

    Do a search on the forum for sleep


    SendKeys

    Do a search on the forum for senkeys
    Man, don't go thinking to hard LoL.

  6. #6
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611
    Sorry it is still early, and I didn't sleep enough . But I still want to help hem, so SORRY for the short and lazy answers.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83
    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

  8. #8
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611
    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:
    1. Dim CalcVal, I
    2. CalcVal = Shell("calc.exe", 1)   ' Run Calculator.
    3. AppActivate CalcVal    ' Activate the Calculator.
    4. For I = 1 To 10  ' Set up counting loop.
    5.    SendKeys I & "{+}", True   ' Send keystrokes to Calculator
    6. Next I   ' to add each value of I.
    7. SendKeys "=", True   ' Get grand total.
    8. msgbox "Sum visable in calculator "
    9. SendKeys "%{F4}", True   ' Send ALT+F4 to close Calculator.

    It might get you "on the road"

  9. #9
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068
    Nah, no need to be sorry I just got a laugh out of it was all, had to remark.

  10. #10
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611
    Now I'm awak, my posts look really stupid, this morning they look handy...

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    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.

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83
    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!
    Last edited by poopyman67; Aug 26th, 2003 at 04:40 PM.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83
    hello??? can any1 help me??

  14. #14
    Hyperactive Member alacritous's Avatar
    Join Date
    Aug 2003
    Posts
    464
    VB Code:
    1. 'Module!
    2. Public Declare Function GetTickCount Lib "kernel32" () As Long
    3. Sub Pause(Length As Long)
    4. Dim OldTime As Long
    5. OldTime = GetTickCount
    6. Do
    7. DoEvents
    8. If GetTickCount >= OldTime + Length Then Exit Do
    9. Loop
    10. End Sub
    11.  
    12. 'Form
    13. Pause (1000)'1 second  Pause (50) is probably good for typing
    14.  
    15.  
    16. 'Typer
    17. Function Add(strMessage As String) As String
    18. Dim i As Integer
    19. For i = 1 To Len(strMessage)
    20. Label1.Caption = Label1.Caption & Mid$(strMessage, i, 1)
    21. Pause (100)
    22. Next
    23. End Function
    24.  
    25. 'caller
    26. Add (Text1.Text)

    *CHEERS*
    alacritous
    Last edited by alacritous; Aug 26th, 2003 at 06:36 PM.

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83
    thx alot alacritous, but when i put it into vb, it didn't work, can u help me??

  16. #16
    Hyperactive Member alacritous's Avatar
    Join Date
    Aug 2003
    Posts
    464
    *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

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83
    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)

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83
    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??

  19. #19
    Hyperactive Member Knowledge_is_Et's Avatar
    Join Date
    Dec 2001
    Location
    An Oak.
    Posts
    305
    Alacritiouses code should work, lemme just make it so you can copy and paste it into your form.

    VB Code:
    1. 'Module!
    2. Public Declare Function GetTickCount Lib "kernel32" () As Long
    3.  
    4. private Sub Pause(Length As Long)
    5. Dim OldTime As Long
    6. OldTime = GetTickCount
    7. Do
    8. DoEvents
    9. If GetTickCount >= OldTime + Length Then Exit Do
    10. Loop
    11. End Sub
    12.  
    13. private sub form_activate
    14. dim strmessage as string
    15. strmessage = "this is a test"
    16. Dim i As Integer
    17. For i = 1 To Len(strMessage)
    18. Label1.Caption = Label1.Caption & Mid$(strMessage, i, 1)
    19. Pause (100)
    20. Next
    21.  
    22. end sub

    that should work, just make sure to put a label on the form before you run it.
    Now returning to the world of VB. Please make sure your seatbelts are securely fastened and all trays are in their upright and locked position.

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83
    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!

  21. #21
    Hyperactive Member alacritous's Avatar
    Join Date
    Aug 2003
    Posts
    464
    it says
    VB Code:
    1. 'Module code
    ..

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83
    ok, so, whats up with the error???

  23. #23
    Hyperactive Member alacritous's Avatar
    Join Date
    Aug 2003
    Posts
    464
    if this doesn't work..screw it
    VB Code:
    1. 'Module!
    2. Public Declare Function GetTickCount Lib "kernel32" () As Long
    3.  
    4. private Sub Pause(Length As Long)
    5. Dim OldTime As Long
    6. OldTime = GetTickCount
    7. Do
    8. DoEvents
    9. If GetTickCount >= OldTime + Length Then Exit Do
    10. Loop
    11. End Sub
    12.  
    13. 'Form
    14. private sub form_activate
    15. dim strmessage as string
    16. strmessage = "this is a test"
    17. Dim i As Integer
    18. For i = 1 To Len(strMessage)
    19. Label1.Caption = Label1.Caption & Mid$(strMessage, i, 1)
    20. Pause (100)
    21. Next
    22.  
    23. end sub
    ...you got to read

  24. #24
    Hyperactive Member Knowledge_is_Et's Avatar
    Join Date
    Dec 2001
    Location
    An Oak.
    Posts
    305
    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.
    Now returning to the world of VB. Please make sure your seatbelts are securely fastened and all trays are in their upright and locked position.

  25. #25

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83
    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:
    1. Private Sub Command1_Click()
    2. Dim strmessage As String
    3. strmessage = Text1.Text
    4. Dim i As Integer
    5. For i = 1 To Len(strmessage)
    6. Label1.Caption = Label1.Caption & Mid$(strmessage, i, 1)
    7. Pause (100)
    8. Next
    9. End Sub

    but how would I change it to use sendkeys?? could i just do:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim strmessage As String
    3. strmessage = Text1.Text
    4. Dim i As Integer
    5. For i = 1 To Len(strmessage)
    6. SendKeys = "Mid$(strmessage, i, 1)"
    7. Pause (100)
    8. Next
    9. End Sub
    or would i have to change more??
    Last edited by poopyman67; Aug 29th, 2003 at 12:29 AM.

  26. #26

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83
    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??

  27. #27
    Hyperactive Member alacritous's Avatar
    Join Date
    Aug 2003
    Posts
    464
    VB Code:
    1. SendKeys = "Mid$(strmessage, i, 1)"
    needs to be changed to

    VB Code:
    1. SendKeys Mid$(strmessage, i, 1)

  28. #28

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83

    hellohello how are you

    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.....
    Last edited by poopyman67; Aug 30th, 2003 at 11:48 PM.

  29. #29
    Hyperactive Member alacritous's Avatar
    Join Date
    Aug 2003
    Posts
    464
    Hello,

    VB Code:
    1. Dim Stop as Boolean
    2.  
    3. Private Sub Command1_Click()
    4. Dim strmessage As String
    5. strmessage = Text1.Text
    6. Dim i As Integer
    7. For i = 1 To Len(strmessage)
    8. If Stop = True Then
    9. Stop = False
    10. Exit Sub
    11. End If
    12. SendKeys Mid$(strmessage, i, 1)
    13. Pause (100)
    14. Next
    15. End Sub
    16.  
    17. Private Sub Command1_Click()
    18. Stop = True
    19. End Sub

    I havn't tested it, but it should work...

    *CHEERS*
    alacritous

  30. #30

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83
    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......

  31. #31
    Hyperactive Member alacritous's Avatar
    Join Date
    Aug 2003
    Posts
    464
    VB Code:
    1. Dim CANCELIT As Boolean
    2.  
    3. Private Sub Command1_Click()
    4. Label1.Caption = ""
    5. Add (Text1.Text)
    6. End Sub
    7.  
    8. Private Sub Command2_Click()
    9. CANCELIT = True
    10. End Sub
    11.  
    12. Function Add(strMessage As String) As String
    13. Dim i As Integer
    14. For i = 1 To Len(strMessage)
    15. If CANCELIT = True Then
    16. CANCELIT = False
    17. Exit Function
    18. End If
    19. Sendkeys Mid$(strMessage, i, 1)
    20. Pause (100)
    21. Next
    22. End Function

    Command1, Command2, Label1, Text1

    Works for me...
    *CHEERS*
    alacritous
    Last edited by alacritous; Sep 2nd, 2003 at 09:22 PM.

  32. #32

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    83
    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:
    1. Dim CANCELIT As Boolean
    2. Private Sub Pause(Length As Long)
    3. Dim OldTime As Long
    4. OldTime = GetTickCount
    5. Do
    6. DoEvents
    7. If GetTickCount >= OldTime + Length Then Exit Do
    8. Loop
    9. End Sub
    10. Private Sub Command1_Click()
    11. Dim Acc As Integer
    12. If IsNumeric(Text2.Text) Then
    13. Acc = Text2.Text
    14. Else
    15. MsgBox "Please enter a numeric value"
    16. End If
    17. Pause (1000)
    18. Function Add(strMessage As String) As String
    19. strMessage = Text1.Text
    20. Dim i As Integer
    21. For i = 1 To Len(strMessage)
    22. If CANCELIT = True Then
    23. CANCELIT = False
    24. Exit Function
    25. End If
    26. SendKeys Mid$(strMessage, i, 1)
    27. Pause (Acc)
    28. Next
    29. End Function
    30. End Sub
    31.  
    32. Private Sub Command2_Click()
    33. Text1.Text = ""
    34. End Sub
    35.  
    36. Private Sub Command3_Click()
    37. CANCELIT = True
    38. End Sub

  33. #33
    Hyperactive Member alacritous's Avatar
    Join Date
    Aug 2003
    Posts
    464
    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
    Attached Files Attached Files

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