Virtual mouse click inside a webbrowser at a specific x and

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts Page 1 of 1
Contributors
User avatar
skyteam
Member
Member
Posts: 27
Joined: Thu Apr 28, 2011 1:27 am

Hi guys so my problem is that the mouse moves and I don't want it to move here the code I have
Code: Select all
    Declare Function mouse_event Lib "user32.dll" Alias "mouse_event" (ByVal dwFlags As Int32, ByVal dX As Int32, ByVal dY As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) As Boolean

    Public Const MOUSE_LEFTDOWN = &H2
    Public Const MOUSE_LEFTUP = &H4


    Private Sub RouletteXPro_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Timer2.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim x As Int32, y As Int32

        'Change 'WebBrowser1.Width\2' and 'WebBrowser1.Height\2' to where ever you want the event to occur
        'but remember to keep it within the webBrowser's size range.
        x = WebBrowser1.Width - 100
        y = WebBrowser1.Height - 100
        'This will click dead center of the webBrowser.
        Call mouse_event(MOUSE_LEFTDOWN, x, y, 0, 0)
        Call mouse_event(MOUSE_LEFTUP, x, y, 0, 0)
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Label1.Text = Val(Label1.Text) - 1
        If Label1.Text = 0 Then
            Timer1.Enabled = False
        End If

    End Sub
but this does not work this is in visual basic 2010
User avatar
skyteam
Member
Member
Posts: 27
Joined: Thu Apr 28, 2011 1:27 am

= ( 30 views but no one can help I am about to give up on this code
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

the mouse moves and I don't want it to move
It would probably be easier if you used this code:
Code: Select all
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Dim x As Integer = WebBrowser1.Width - 100
        Dim y As Integer = WebBrowser1.Height - 100

        Cursor.Position = New Point(x, y)
    End Sub
This will move the cursor to the point at x and y.
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4392
Joined: Tue Aug 04, 2009 1:47 am

The mouse has to move in order for it to click in the spot you want to click. Maybe you could store the current mouse coordinates before doing the click and then return the mouse to that point afterwards.

If your trying to click a button or something on a web page then it would be easier and better to use the element invoke click method instead :?
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
skyteam
Member
Member
Posts: 27
Joined: Thu Apr 28, 2011 1:27 am

CodenStuff wrote:
The mouse has to move in order for it to click in the spot you want to click. Maybe you could store the current mouse coordinates before doing the click and then return the mouse to that point afterwards.

If your trying to click a button or something on a web page then it would be easier and better to use the element invoke click method instead :?
I have thought of that, thing is that I would like the form to minimize and still keep clicking the X and Y positions there is more then one
5 posts Page 1 of 1
Return to “Coding Help & Support”