Results 1 to 13 of 13

Thread: SendKeys - Hold Down a Key

Threaded View

  1. #1

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Question SendKeys - Hold Down a Key

    Hey guys! It's been awhile. I've Googl(ed?) this for a few hours and can't seem to find a straight forward answer. I'm working on a program and I can't seem to figure out how to make SendKeys actually Hold Down a key.

    If I do this-

    Code:
    SendKeys.Send(W)
    Loop
    Then it literally spams the key as fast as possible. I just need it to hold down the key. I found this bit of code but I don't really understand how to utilize it-

    Code:
    Private Sub LetKeyGo(ByVal key As Byte)
    
    Const SPI_GETKEYBOARDDELAY = 22
        Const SPI_GETKEYBOARDSPEED = 10
        Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
        Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Integer, ByVal wMapType As Integer) As Integer
        Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, ByRef lpvParam As Integer, ByVal fuWinIni As Integer) As Integer
    
            Dim kb_delay As Integer
            Dim kb_speed As Integer
    
    
            SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, kb_delay, 0)
            SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, kb_speed, 0)
    
    
    
            keybd_event(key, MapVirtualKey(key, 0), 2, 0)
    
        End Sub
        Private Sub HoldKeyDown(ByVal key As Byte)
    
            Dim kb_delay As Integer
            Dim kb_speed As Integer
    
    
            SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, kb_delay, 0)
            SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, kb_speed, 0)
    
    
    
            keybd_event(key, MapVirtualKey(key, 0), 0, 0)
        End Sub
    Any help would be great! Thanks.
    Last edited by HunterTTP; Jan 12th, 2013 at 09:50 AM.

Tags for this Thread

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