Mouse click on dirextx objects [help needed]
I've Searched every part of the forum and almost all the internet googling the answer.
2 Week's have passed, still looking for an answer, the thing is:
I wanna to make a simulation of mouse click in a certain point of screen.
This point is inside a game called Point Blank, by On Game. Im trying to do the following automatically.
Open up the game. Fill in the account. Put the password. Click the login button. Double Click the server and Double Click the room.
The Problem:
The is no way on posting,sending messages or other windows api that would do such a thing. (at least that i've found!)
I've tryed:
PostMessage
SendMessage
SendInput
Ideas:
Is there a way to do it in a lower level programming language? If yes, please how?
Any doubts post a reply.
Thanks in Advance
Re: Mouse click on dirextx objects [help needed]
There is a mouse_event sub which should be used
Code:
Public Class Form1
Private Declare Function SetCursorPos Lib "User32.dll" (ByVal X As Int32, ByVal Y As Int32) As Int32
Private Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Int32, ByVal dx As Int32, ByVal dy As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32)
Private Const MOUSEEVENTF_LEFTDOWN As Int32 = &H2
Private Const MOUSEEVENTF_LEFTUP As Int32 = &H4
Private Const MOUSEEVENTF_RIGHTDOWN As Int32 = &H8
Private Const MOUSEEVENTF_RIGHTUP As Int32 = &H10
Private Const MOUSEEVENTF_MIDDLEDOWN As Int32 = &H20
Private Const MOUSEEVENTF_MIDDLEUP As Int32 = &H40
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Go to point 800, 300
SetCursorPos(800, 300)
' Simulate left click.
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' Go to point 40, 460
SetCursorPos(40, 460)
' Simulate right click.
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
End Sub
End Class
Re: Mouse click on dirextx objects [help needed]
hey dude!
Thanks for replying, but this functions is only aplied to desktop apps. So it wont work.
Thanks anyhow.
Any other idea?
See ya.
Re: Mouse click on dirextx objects [help needed]
All you are doing is making a macro. 4x2y's code should work just fine. It simulated mouse clicks which should work on any game.
Re: Mouse click on dirextx objects [help needed]
Quote:
Originally Posted by
MotoX646
All you are doing is making a macro. 4x2y's code should work just fine. It simulated mouse clicks which should work on any game.
As you said, it "SHOULD", but it doesnt.
Thanks anyway.
Anyother tip or help?
Re: Mouse click on dirextx objects [help needed]
Yes, it should. If it doesn't then you are doing something wrong.
Can you describe your setup better? Is the game not a desktop app? Is your app not a desktop app?
I've used the method above on DirectX games plenty of times.
Re: Mouse click on dirextx objects [help needed]
Quote:
Originally Posted by
MotoX646
Yes, it should. If it doesn't then you are doing something wrong.
Can you describe your setup better? Is the game not a desktop app? Is your app not a desktop app?
I've used the method above on DirectX games plenty of times.
Ok, It WORKS ON ALMOST ANY DX GAME like Warcraft and so on...
This game made by OnGame it doesnt. My app is a normal Vb.Net one.
Nothing unusual.
Take a look at "Point Blank" if you can and see by yourself this strange thing.
I am so glad that there are a lot of people trying to help, Thanks You. :)
Any other Idea would be greate!
See ya.
Re: Mouse click on dirextx objects [help needed]
The code
Code:
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Simulates left click regardless of what is on the screen.
I don't have "Point Blank" game to test the code with it, i have two question, is the game configured to use mouse? are you sure you are click on the correct point?
Re: Mouse click on dirextx objects [help needed]
Quote:
Originally Posted by
4x2y
The code
Code:
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Simulates left click regardless of what is on the screen.
I don't have "Point Blank" game to test the code with it, i have two question, is the game configured to use mouse? are you sure you are click on the correct point?
Yes, it uses the mouse and yes too I am sure that i'm clicking on the right place.
I tryed the same code and could not get it working...
Ok, i think that is impossible to do so.
Consider this Thread finished and unsolved.
3 Week's of sarching and no answer. But ok.
Thanks for all the help requested.
See ya.
Re: Mouse click on dirextx objects [help needed]
You got the answer. I just don't think you are doing it correctly.
If you can click it with a real mouse, you can use the code suggested by 4x2y to click it. It is basically the same thing.
Re: Mouse click on dirextx objects [help needed]
@henriqueshb
I have got an idea it maybe the reason for the problem, just give it a try!!!
How do you execute the code?
I mean, if you click on a button in your main form, probably the cursor go to the game and the click by mouse_event is just transfer the focus from your form to the game window, so try to send left click twice
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Go to point 800, 300
SetCursorPos(800, 300)
' Simulate left click.
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
or put the code in a timer event to be sure it will be executed when the game window has the focus.
Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' Go to point 800, 300
SetCursorPos(800, 300)
' Simulate left click.
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
Re: Mouse click on dirextx objects [help needed]
Quote:
Originally Posted by
4x2y
@
henriqueshb
I have got an idea it maybe the reason for the problem, just give it a try!!!
How do you execute the code?
I mean, if you click on a button in your main form, probably the cursor go to the game and the click by mouse_event is
just transfer the focus from your form to the game window, so try to send left click twice
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Go to point 800, 300
SetCursorPos(800, 300)
' Simulate left click.
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
or put the code in a timer event to be sure it will be executed when the game window has the focus.
Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' Go to point 800, 300
SetCursorPos(800, 300)
' Simulate left click.
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
Yes man, Actually i did the last part of the code.
Puted into a timer and dit not get it working.
No more ideas.
I dont know, only in this game it doesnt work.
Any other idea?
Thanks at all.
Re: Mouse click on dirextx objects [help needed]
The nearest i reached was when not focused on the game window and then sent a click it got focused on the game window,
so it is clicking, but the game does not consider the things that comes from the normal way we post the messages of this kind,
like clicking, i don't realy know why. But it does not respond to those commands we have been talking...
Anyway, thanks for the help till now. And also sorry for the english mistakes...
Re: Mouse click on dirextx objects [help needed]
No more help?!
Ok then, thanks at all anyway. Seeya.
Re: Mouse click on dirextx objects [help needed]
Quote:
Originally Posted by
henriqueshb
No more help?!
Last one :bigyello:
According to MSDN, the mouse_event has been superseded, so let's try SendInput
I have created VB6 code for using SendInput, but i have trouble converting it to VB.NET (specially trouble with CopyMemory API function), so try it with that game and if it worked then convert it to VB.NET and please share the result. :D
Code:
Option Explicit
Private Const MOUSEEVENTF_LEFTDOWN As Long = &H2
Private Const MOUSEEVENTF_LEFTUP As Long = &H4
Private Const INPUT_MOUSE As Long = 0
Private Type MOUSEINPUT
dx As Long
dy As Long
mouseData As Long
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type
Private Type GENERALINPUT
dwType As Long
xi(0 To 23) As Byte
End Type
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Sub Command1_Click()
Dim typInputType As GENERALINPUT
Dim typMouseInput As MOUSEINPUT
SetCursorPos 900, 40
typInputType.dwType = INPUT_MOUSE
' Send left button DOWN
typMouseInput.dwFlags = MOUSEEVENTF_LEFTDOWN
CopyMemory typInputType.xi(0), typMouseInput, Len(typMouseInput)
SendInput 1, typInputType, Len(typInputType)
' Send left button UP
typMouseInput.dwFlags = MOUSEEVENTF_LEFTUP
CopyMemory typInputType.xi(0), typMouseInput, Len(typMouseInput)
SendInput 1, typInputType, Len(typInputType)
End Sub
Re: Mouse click on dirextx objects [help needed]
Ok, I'll try it later, but it will be in something like 12 hours...
I'm at work and got go to the university later...
So, see you later, I'll convert and share later for sure.
This is not that hard wait till that or take a look here tomorrow.
Re: Mouse click on dirextx objects [help needed]
Quote:
Originally Posted by
4x2y
Last one :bigyello:
According to MSDN, the
mouse_event has been superseded, so let's try
SendInput
I have created VB6 code for using SendInput, but i have trouble converting it to VB.NET (specially trouble with CopyMemory API function), so try it with that game and if it worked then convert it to VB.NET and
please share the result. :D
Code:
Option Explicit
Private Const MOUSEEVENTF_LEFTDOWN As Long = &H2
Private Const MOUSEEVENTF_LEFTUP As Long = &H4
Private Const INPUT_MOUSE As Long = 0
Private Type MOUSEINPUT
dx As Long
dy As Long
mouseData As Long
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type
Private Type GENERALINPUT
dwType As Long
xi(0 To 23) As Byte
End Type
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Sub Command1_Click()
Dim typInputType As GENERALINPUT
Dim typMouseInput As MOUSEINPUT
SetCursorPos 900, 40
typInputType.dwType = INPUT_MOUSE
' Send left button DOWN
typMouseInput.dwFlags = MOUSEEVENTF_LEFTDOWN
CopyMemory typInputType.xi(0), typMouseInput, Len(typMouseInput)
SendInput 1, typInputType, Len(typInputType)
' Send left button UP
typMouseInput.dwFlags = MOUSEEVENTF_LEFTUP
CopyMemory typInputType.xi(0), typMouseInput, Len(typMouseInput)
SendInput 1, typInputType, Len(typInputType)
End Sub
Just for you to know, i have already tryed the sendinput function but does not work either.
1 Attachment(s)
Re: Mouse click on dirextx objects [help needed]
Strange, I tested SendInput and it works with that game, see attached video, when i click on Command1, the cursor go to the game's close button and simulate left click and as you can see the confirmation message appear.
mouse_event was not work as you said!!!
BTW: i cannot start the game, as when i click on its start button, the game takes sometime to load then terminate.
Re: Mouse click on dirextx objects [help needed]
Actually, this is not the game part, in this part everthing works....
The part of the game that does not work is after the loading part...
And a NOTICE:
I found what we should take a look.
And it is "dinput8.dll" this is what does the magic.
If this dll is not working you cant send any input to the game even using the real mouse or keyboard.
In this way I think that should have some kind of communication with this dll, I googled it but could not found any.
And 4x2y your probably the best guy i have ever know, thanks for all you help.
See ya.