Results 1 to 9 of 9

Thread: Sendkeys Wait Time

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    1

    Sendkeys Wait Time

    Hi guys, im new here and i have some questions.

    lately i tried to write a code in VB 6 that send keys that i type in the running code into a text box.

    my question is how do i make a time wait that i defined between every key and key?

    thanks for the help

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Sendkeys Wait Time

    Welcome to the forums

    Here's a pice of code that can help you get started:
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
      sendKey "H", 5000
      sendKey "e", 200
      sendKey "y", 200
      sendKey ",", 200
      sendKey " ", 200
      sendKey "d", 200
      sendKey "u", 200
      sendKey "d", 200
      sendKey "e", 200
      sendKey "!", 200
    End Sub
    
    Public Sub sendKey(ByRef key As String, ByRef waitMS As Integer)
      On Error GoTo errHandeler
      
      Dim endTime As Single
      
      waitMS = Abs(waitMS)
      
      endTime = (Timer + (waitMS / 1000))
      
      Do While Timer <= endTime
        DoEvents
      Loop
      
      SendKeys key
      
      Exit Sub
    errHandeler:
    End Sub

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Sendkeys Wait Time

    Unless that is really what you want, The SendKeys statement has an optional second parameter called [wait]:
    SendKeys Statement
    Sends one or more keystrokes to the active window as if typed at the keyboard.
    Syntax
    SendKeys string[, wait]
    ... ...
    Wait : Optional. Boolean value specifying the wait mode.
    If False (default), control is returned to the procedure immediately after the keys are sent.
    If True, keystrokes must be processed before control is returned to the procedure.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  4. #4
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: Sendkeys Wait Time

    Quote Originally Posted by anhn
    Unless that is really what you want, The SendKeys statement has an optional second parameter called [wait]:
    Yes, but that's not what wait(Bool) is used for.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  5. #5
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Sendkeys Wait Time

    Quote Originally Posted by CDRIVE
    Yes, but that's not what wait(Bool) is used for.
    What do you mean CDRIVE?

    I already stated "Unless that is really what you want", that means he really want to delay the keystroke as gavio shown.

    For sure, [wait] won't delay but it makes the code waits for the previous keystroke to be processed before it sends the next keystroke.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Sendkeys Wait Time

    My thoughts are that using the SendKeys function should be avoided as that will present an problem if the OP ever moves to Vista.

  7. #7
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Sendkeys Wait Time

    I agree. Should only use it when you have no other choice.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  8. #8
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: Sendkeys Wait Time

    Quote Originally Posted by anhn
    What do you mean CDRIVE?

    I already stated "Unless that is really what you want", that means he really want to delay the keystroke as gavio shown.

    For sure, [wait] won't delay but it makes the code waits for the previous keystroke to be processed before it sends the next keystroke.
    Anhn:
    This is weird! I apologized (last night) for misconstruing your statement but it never made it to the board??

    Anyway.... SORRY!
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  9. #9
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Sendkeys Wait Time

    Never mind, mate! (Aussie term)
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

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