Home All Groups Group Topic Archive Search About
Author
17 Jul 2006 2:50 AM
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.

Author
17 Jul 2006 5:06 AM
Cor Ligthert [MVP]
Daniel,

I don't see much VBNet code in what you show, it is more using VBNet to code
Win32

However usualy is doing this just done by setting a keydown switch which is
togled.

Here a sample with some dynamic controls that you can mode over your screen
completely with VBNet code..

http://www.vb-tips.com/dbPages.aspx?ID=c1be07ed-e66b-4080-bc11-47ef665ea0c2

I hope this helps,

Cor

Show quoteHide quote
"Daniel N" <saintdark_***@yahoo.com> schreef in bericht
news:aXCug.2437$nj6.687@fe08.lga...
> 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.
>
>
Author
17 Jul 2006 10:40 AM
Herfried K. Wagner [MVP]
"Daniel N" <saintdark_***@yahoo.com> schrieb:
> 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
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>