[VB.net] Clicks in another program at special coordinates
Hi,
I want to simulate clicks in another program at special coordinates, without having the program opened (multitasking).
Does somebody happen to know how?
Regards :P
You can use P/Invokes. All you need to do is grab the main windows handle, and invoke "SendMessage" with a mouse click and it will work.
EDIT: Found the sample code:
Code:
<DllImport("user32.dll", CharSet := CharSet.Auto, SetLastError := False)> _
Private Shared Function SendMessage(hWnd As IntPtr, Msg As Integer, wParam As Integer, lParam As Integer) As IntPtr
End Function
<StructLayout(LayoutKind.Explicit)> _
Structure LParamLocation
<FieldOffset(0)> _
Private Number As Integer
<FieldOffset(0)> _
Public X As Short
<FieldOffset(2)> _
Public Y As Short
Public Shared Widening Operator CType(p As LParamLocation) As Integer
Return p.Number
End Operator
End Structure
Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs)
Dim process = Process.GetProcessesByName("chrome")
Dim points As New LParamLocation()
points.X = CShort(PointToScreen(e.Location).X)
points.Y = CShort(PointToScreen(e.Location).Y)
'MouseLeft down message
SendMessage(process(0).MainWindowHandle, &H201, 0, points)
'MouseLeft up message
SendMessage(process(0).MainWindowHandle, &H202, 0, points)
End Sub
If i remember right, this approach has some drawbacks, there are quite some applications that fetch their input deeper down on the driver, if they use directinput as example.
Just FYI if you have problems getting this code working
Yep. Makes sense, Just going back over our codebase and read through our input injection. We use kernel mode injection techniques to inject input directly in as if it came from the driver. There's also some really nice DirectInput hooking code in there too that we use to override some DirectInput methods in user space so we have the ability to inject input that way, however it seems this is a tad overkill to be posting code samples of as it requires a lot higher level of knowledge than the OP probably has!
You can use P/Invokes. All you need to do is grab the main windows handle, and invoke "SendMessage" with a mouse click and it will work.
EDIT: Found the sample code:
Code:
<DllImport("user32.dll", CharSet := CharSet.Auto, SetLastError := False)> _
Private Shared Function SendMessage(hWnd As IntPtr, Msg As Integer, wParam As Integer, lParam As Integer) As IntPtr
End Function
[COLOR="Cyan"]<StructLayout(LayoutKind.Explicit)> _
Structure LParamLocation
<FieldOffset(0)> _
Private Number As Integer
<FieldOffset(0)> _
Public X As Short
<FieldOffset(2)> _
Public Y As Short
Public Shared Widening Operator CType(p As LParamLocation) As Integer
Return p.Number
End Operator
End Structure[/COLOR]
Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs)
Dim process = Process.GetProcessesByName("chrome")
Dim points As New LParamLocation()
points.X = CShort(PointToScreen(e.Location).X)
points.Y = CShort(PointToScreen(e.Location).Y)
'MouseLeft down message
SendMessage(process(0).MainWindowHandle, &H201, 0, points)
'MouseLeft up message
SendMessage(process(0).MainWindowHandle, &H202, 0, points)
End Sub
-jD
Hey, thanks for the info.
What is the structure thing for?
Regards
The parameters variable for that particular message takes a single integer for both the X and Y values. It takes what's called the upper and lower bits of the single integer to determine which coordinate to click on. If you think of an integer, it's 4 bytes correct? What the click parameter does is it takes the lower 2 bytes for the X value and the upper 2 bytes for the Y value. The LayoutKind.Explicit attribute says to windows that you want to explicitly control how that struct looks in memory. What it's doing here is it's overlapping the X and Y shorts over the same memory space as the integer. Because a short is 2 bytes, this has the same effect of setting the lower and higher bytes of an integer. To make things even simpler, I implemented an explicit cast operator to cast to the integer the SendMessage expects seamlessly! When I'm home I'll post some images to make it easier to understand.
[RELEASE]Special Purchase Program DO by HackMaster 08/14/2012 - DarkOrbit - 16 Replies Special Purchase Program DO by HackMaster
- With this program you can buy special things are not for sale
instructions:
- Choose your language ... ESP (Spanish) or ENG (English)
- Put your server code
- Click on the offer you like best
Please click on the advertising to get everything I need:
Program buy special ammunition. 01/10/2012 - DarkOrbit - 20 Replies Good evening,
I know how to give guys the link of that program to buy ammunition x5, etc. detachers. without it there is the x3?
Thank you.