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-
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-
Any help would be great! Thanks.
If I do this-
Code:
SendKeys.Send(W)
Loop
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