Holding down a key

D

Daniel N

Is there a way to hold down keys in vb.net?

In the program I am writing I can simulate a MOUSE button hold down:



Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx
As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As
Long)

Public Const MOUSEEVENTF_LEFTDOWN As Object = &H2

Public Const MOUSEEVENTF_LEFTUP As Object = &H4



Public Sub LeftDown()

mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)

End Sub

Public Sub LeftUp()

mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

End Sub



Public Sub LeftClick()

LeftDown()

LeftUp()

End Sub



So I am Sure I can do this with a keyboard key (Specifically ALT, and the
SHIFT keys). Sendkeys does not work (Its much like a click by sending a down
AND an UP). As you can see I googled and found that using the hex &H2 to
simulate a mouse button click worked I am sure there is a way to do it for
the keyboard. Thanks if you can provide help.
 
H

Herfried K. Wagner [MVP]

Daniel N said:
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal
dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As
Long)

Public Const MOUSEEVENTF_LEFTDOWN As Object = &H2

Public Const MOUSEEVENTF_LEFTUP As Object = &H4

=>

\\\
Public Declare Sub mouse_event Lib "user32.dll" ( _
ByVal dwFlags As Int32, _
ByVal dx As Int32, _
ByVal dy As Int32, _
ByVal cButtons As Int32, _
ByVal dwExtraInfo As Int32 _
)

Public Const MOUSEEVENTF_LEFTDOWN As Int32 = &H2
Public Const MOUSEEVENTF_LEFTUP As Int32 = &H4
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top