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?
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
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?
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...
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
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.
Last edited by henriqueshb; Sep 18th, 2012 at 05:54 AM.
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...
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.
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
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.
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.
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.