Results 1 to 7 of 7

Thread: mouse button

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    118

    mouse button

    Hi,

    How can I send a click with my mouse in vb.net 2010?

    the old way in vb6 isnt working

    Code:
        Private 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)
        Private Const mouseclickup = 4
        Private Const mouseclickdown = 2
    Code:
            '  mouse_event(mouseclickdown, 0, 0, 0, 0)
            '  mouse_event(mouseclickup, 0, 0, 0, 0)
    who can help me out?

  2. #2
    Junior Member
    Join Date
    Mar 2012
    Posts
    17

    Re: mouse button

    If you have a form application, this should work:
    Code:
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            AddHandler Me.MouseClick, AddressOf Me.HandleMouse
        End Sub
    
        Private Sub HandleMouse(sender As Object, e As MouseEventArgs)
    
        End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    118

    Re: mouse button

    Quote Originally Posted by CrazyVB View Post
    If you have a form application, this should work:
    Code:
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            AddHandler Me.MouseClick, AddressOf Me.HandleMouse
        End Sub
    
        Private Sub HandleMouse(sender As Object, e As MouseEventArgs)
    
        End Sub
    no sorry i mean something like the sendkeys function in vb.net, but isntead its sending keys it should send a mouse click left or right.
    how do you do something like that?

  4. #4
    Junior Member
    Join Date
    Mar 2012
    Posts
    17

    Re: mouse button

    Is this what you mean?
    Code:
    Dim x As Integer = 1 'x position of the click
    Dim y As Integer = 1 'y position of the click
    Dim button As Windows.Forms.MouseButtons = Windows.Forms.MouseButtons.Left 'Button to be pressed
    Dim delta As Integer = 0 'Scroll wheel movement
    Dim ev As New MouseEventArgs(button, clicks, x, y, delta)
    OnMouseClick(ev)

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: mouse button

    but isntead its sending keys it should send a mouse click left or right.
    This doesn't really make any sense. A mouse click never exists in isolation from a position on the screen and what's there. Perhaps if you could be a bit more specific about what you want the click sent to (and why) it would help us to help you properly.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: mouse button

    It's probably not in isolation... generally there's a mouse move kind of command, to put the cursor at a specific spot... say... on a button for instance... followed by the click message... which would then click the button... sounds like possibly the OP has the mouse move messages down, and now needs to send the WM_LBUTTONDOWN message...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: mouse button

    If the mouse_event function worked for you in VB6 it will work for you in VB.Net. Just change all the arguments from Long to Integer in the declaration. You also need to specify the type for your constants.
    Code:
    Private Const mouseclickup As Integer = 4
    Last edited by Joacim Andersson; Feb 26th, 2013 at 07:02 AM.

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