Results 1 to 12 of 12

Thread: Autotyper

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    87

    Wink 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

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    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!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    87
    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

  4. #4
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    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!

  5. #5
    Lively Member Bootking's Avatar
    Join Date
    Mar 2003
    Location
    Marquette University
    Posts
    90
    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:
    1. Const myString = "Check out my band's site at walterwalker.com"
    2.  
    3. Sub Command1_Click()
    4.     Timer1.enabled = True
    5. End Sub
    6.  
    7. Sub Timer1_Timer()
    8.     Static X as Integer
    9.     X = X + 1
    10.     If X <= len(myString) Then
    11.         Text1 = left(myString, x)
    12.     Else
    13.         Timer1.Enabled = False
    14.     End If
    15. 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:
    1. Const myString = "Walter Walter Rocks!"
    2.  
    3. Sub Command1_Click()
    4.     Timer1.enabled = True
    5. End Sub
    6.  
    7. Sub Timer1_Timer()
    8.     Static X as Integer
    9.     X = X + 1
    10.     If X <= len(myString) Then
    11.         Sendkeys Mid(myString, 1, 1), True
    12.     Else
    13.         Timer1.Enabled = False
    14.     End If
    15. End Sub
    Check out my band's website!
    Walter Walker Band

  6. #6
    Hyperactive Member Disiance's Avatar
    Join Date
    Sep 2004
    Location
    Denver, CO
    Posts
    439
    Or if he doesn't want to put a timer on the form:

    VB Code:
    1. Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
    2.  
    3. Sub Command1_Click()
    4.  Text1.SetFocus
    5.  SendKeys "C"
    6.  DoEvents
    7.  Sleep 100
    8.  SendKeys "a"
    9.  DoEvents
    10.  Sleep 100
    11.  SendKeys "t"
    12.  DoEvents
    13.  Sleep 100
    14.  SendKeys "s"
    15.  DoEvents
    16.  Sleep 100
    17.  SendKeys " "
    18.  DoEvents
    19.  Sleep 100
    20.  SendKeys "H"
    21.  DoEvents
    22.  Sleep 100
    23.  SendKeys "a"
    24.  DoEvents
    25.  Sleep 100
    26.  SendKeys "t"
    27.  DoEvents
    28.  Sleep 100
    29.  SendKeys "s"
    30. End Sub

    Of course this method turned out hellishly long, but it is another way of doing things

    Disiance

  7. #7
    Hyperactive Member Disiance's Avatar
    Join Date
    Sep 2004
    Location
    Denver, CO
    Posts
    439
    Felt my above was much to long, so here's a better compilation:
    VB Code:
    1. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    2.  
    3. Sub Command1_Click()
    4.     TypeText "Cats Hats", Text1
    5. End Sub
    6.  
    7. Sub TypeText(toType As String, Destination As TextBox)
    8.     Destination.SetFocus
    9.     Dim i As Integer
    10.     For i = 1 To Len(toType)
    11.         SendKeys Mid(toType, i, 1)
    12.         DoEvents
    13.         Sleep 100
    14.     Next i
    15.     SendKeys "{ENTER}" 'Could be replaced with SendKeys "~"
    16. End Sub

    And this will take any amount of characters up to 32,767, limited because of the 'i' variable being an integer.

    Disiance

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    87
    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

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    87
    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

  10. #10
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Zeka, Welcome to the Forum


    Which on of the methods above are you using?

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    87
    Oh yeah, forgot to mention. I found the example Disiance posted works best.

    VB Code:
    1. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    2.  
    3. Sub Command1_Click()
    4.     TypeText "Cats Hats", Text1
    5. End Sub
    6.  
    7. Sub TypeText(toType As String, Destination As TextBox)
    8.     Destination.SetFocus
    9.     Dim i As Integer
    10.     For i = 1 To Len(toType)
    11.         SendKeys Mid(toType, i, 1)
    12.         DoEvents
    13.         Sleep 100
    14.     Next i
    15.     SendKeys "{ENTER}" 'Could be replaced with SendKeys "~"
    16. 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

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    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
  •  



Click Here to Expand Forum to Full Width