|
-
Oct 3rd, 2010, 07:59 PM
#1
Thread Starter
Frenzied Member
Simulate mouse click on form
*Edit
After reading a few things on google, is there a way to just go to x,y from within the form, not the whole window display itslef?
I have some functions i found online.
I want to go to x,y cords from within my form, and move the mouse to it, and simulate a left mouse click.
When i click my button to move the mouse, it puts the mouse way outside my form
Code:
'Button to move mouse and click
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MoveMouse(653, 264)
LeftClick()
End Sub
Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
Public Declare Function SetCursorPos Lib "user32" (ByVal X As Integer, ByVal Y As Integer) As Integer
Public Declare Function GetCursorPos Lib "user32" (ByVal lpPoint As POINTAPI) As Integer
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20
Public Const MOUSEEVENTF_MIDDLEUP = &H40
Public Const MOUSEEVENTF_RIGHTDOWN = &H8
Public Const MOUSEEVENTF_RIGHTUP = &H10
Public Const MOUSEEVENTF_MOVE = &H1
Public Structure POINTAPI
Dim X As Integer
Dim Y As Integer
End Structure
Public Function GetCurrentX() As Integer
Dim Position As POINTAPI
GetCursorPos(Position)
GetCurrentX = Cursor.Position.X
End Function
Public Function GetCurrentY() As Integer
Dim Position As POINTAPI
GetCursorPos(Position)
GetCurrentY = Cursor.Position.Y
End Function
Public Function GetMousePos() As Integer
GetCurrentX()
GetCurrentY()
End Function
Public Sub LeftClick()
LeftDown()
LeftUp()
End Sub
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 MiddleClick()
MiddleDown()
MiddleUp()
End Sub
Public Sub MiddleDown()
Mouse_Event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0)
End Sub
Public Sub MiddleUp()
Mouse_Event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0)
End Sub
Public Sub MoveMouse(ByVal xMove As Integer, ByVal yMove As Integer)
mouse_event(MOUSEEVENTF_MOVE, xMove, yMove, 0, 0)
End Sub
Public Sub RightClick()
RightDown()
RightUp()
End Sub
Public Sub RightDown()
Mouse_Event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
End Sub
Public Sub RightUp()
Mouse_Event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
End Sub
Last edited by joefox; Oct 3rd, 2010 at 08:23 PM.
-
Oct 3rd, 2010, 10:23 PM
#2
Re: Simulate mouse click on form
try this:
vb Code:
'Button to move mouse and click
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p As Point = Me.PointToScreen(New Point(653, 264))
MoveMouse(p.x, p.y)
LeftClick()
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 4th, 2010, 09:01 AM
#3
Thread Starter
Frenzied Member
Re: Simulate mouse click on form
Cool thanks!
Now is there a way to copy whats in textbox1 to where the current mouse is at?
-
Oct 4th, 2010, 09:30 AM
#4
Re: Simulate mouse click on form
 Originally Posted by joefox
Cool thanks!
Now is there a way to copy whats in textbox1 to where the current mouse is at?
how do you mean? draw it on the form, or is the another textbox there?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|