Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 11:39

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[VB.net] Clicks in another program at special coordinates

Discussion on [VB.net] Clicks in another program at special coordinates within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 43
Join Date: Aug 2011
Posts: 497
Received Thanks: 66
[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
Unlocked., is offline  
Old 07/01/2013, 04:21   #2
 
»jD«'s Avatar
 
elite*gold: 237
Join Date: Sep 2010
Posts: 1,152
Received Thanks: 4,910
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
-jD
»jD« is offline  
Thanks
2 Users
Old 07/01/2013, 11:27   #3
 
elite*gold: 100
Join Date: Aug 2005
Posts: 595
Received Thanks: 208
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
dready is offline  
Old 07/01/2013, 14:52   #4
 
»jD«'s Avatar
 
elite*gold: 237
Join Date: Sep 2010
Posts: 1,152
Received Thanks: 4,910
This will actually inject it in the message queue, you will only find issues maybe if its running full screen.

-jD
»jD« is offline  
Old 07/01/2013, 15:02   #5
 
elite*gold: 100
Join Date: Aug 2005
Posts: 595
Received Thanks: 208
Didnt DirectInput ignore the messagequeue ?
dready is offline  
Old 07/01/2013, 16:07   #6


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,904
Received Thanks: 25,407
^Yep.
SendInput injects events directly at the driver layer.
MrSm!th is offline  
Old 07/02/2013, 03:22   #7
 
»jD«'s Avatar
 
elite*gold: 237
Join Date: Sep 2010
Posts: 1,152
Received Thanks: 4,910
Quote:
Originally Posted by MrSm!th View Post
^Yep.
SendInput injects events directly at the driver layer.
So DirectInput does or does not see the events? I'm pretty sure it does because I develop a bot for Diablo III that uses this method...

-jD
»jD« is offline  
Old 07/02/2013, 10:44   #8
 
.SkyneT.'s Avatar
 
elite*gold: 273
Join Date: Sep 2010
Posts: 1,831
Received Thanks: 786
Quote:
Originally Posted by »jD« View Post
So DirectInput does or does not see the events?.
Yes, DirectInput gets everything directly from the driver, and bypasses
the windows message stuff.
.SkyneT. is offline  
Old 07/05/2013, 17:09   #9
 
»jD«'s Avatar
 
elite*gold: 237
Join Date: Sep 2010
Posts: 1,152
Received Thanks: 4,910
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!

Does the SendInput method work OP?

-jD
»jD« is offline  
Old 07/06/2013, 22:34   #10
 
elite*gold: 43
Join Date: Aug 2011
Posts: 497
Received Thanks: 66
Quote:
Originally Posted by »jD« View Post
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
Unlocked., is offline  
Old 07/07/2013, 03:31   #11
 
»jD«'s Avatar
 
elite*gold: 237
Join Date: Sep 2010
Posts: 1,152
Received Thanks: 4,910
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.

-jD
»jD« is offline  
Reply


Similar Threads Similar Threads
[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.



All times are GMT +1. The time now is 11:39.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.