Results 1 to 6 of 6

Thread: VB 6.0: sendkey Holding a button down

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    172

    VB 6.0: sendkey Holding a button down

    I have figured out how to use sendkey to send key presses to other apps, but how would you go about sending a key press and hold to other apps?

    IE: press and hold W for 10 seconds.

  2. #2
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: VB 6.0: sendkey Holding a button down

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Debug.Print KeyCode
        'Place your sendkey code here, it will repeatedly send the code
    End Sub

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

    Re: VB 6.0: sendkey Holding a button down

    Quote Originally Posted by Tontow
    I have figured out how to use sendkey to send key presses to other apps, but how would you go about sending a key press and hold to other apps?

    IE: press and hold W for 10 seconds.
    What is your end goal with this?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    172

    Re: VB 6.0: sendkey Holding a button down

    I was playing around with sendkeys and was just wondering if it could be done without it sending tens of thoushands of repeating keypresses.

  5. #5
    Hyperactive Member
    Join Date
    Aug 2007
    Posts
    269

    Re: VB 6.0: sendkey Holding a button down

    Place a timer on the form and perform the sendkeys in there?

    Code:
    Dim lngCount As Long
    
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Timer1.Enabled = True
    End Sub
    
    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
        Timer1.Enabled = False
        lngCount = 0
    End Sub
    
    Private Sub Timer1_Timer()
    
    If lngCount = 10 Then
        ''sendkeys here
        MsgBox "Key sent"
    End If
    
    lngCount = lngCount + 1
    
    End Sub

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    172

    Re: VB 6.0: sendkey Holding a button down

    You missunderstood, I want to send the keydown and keyup events to another app.

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