I have a game written in Directx (not mine it's mmo game). The game window isn't active (not minimized, just it's behind other windows but if is possible it can be minimized also).
I want to simulate mouse click on x, y position.
Spy++ doesn't show anything in message when i'm clicking in game.
For now i did just that:
private void start_Click(object sender, EventArgs e)
{
IntPtr ActualWindow = GetActiveWindow();
ShowWindow(hWnd, ShowWindowCommands.Restore); //show game window
Thread.Sleep(50); //a little slow down
ClickOnPoint(hWnd, new Point(692, 87)); //click on x,y
Thread.Sleep(50); //again a little slow down
ShowWindow(hWnd, ShowWindowCommands.Minimize);//minimize game window
ShowWindow(ActualWindow, ShowWindowCommands.Restore);//restore last active window
//sleep is needed for click, if i will do it too fast game will not detect the click
}
private void ClickOnPoint(IntPtr wndHandle, Point clientPoint)
{
POINT oldPoint;
GetCursorPos(out oldPoint);
ClientToScreen(wndHandle, ref clientPoint);
/// set cursor on coords, and press mouse
SetCursorPos(clientPoint.X, clientPoint.Y);
mouse_event(0x00000002, 0, 0, 0, UIntPtr.Zero); /// left mouse button down
Thread.Sleep(18);
mouse_event(0x00000004, 0, 0, 0, UIntPtr.Zero); /// left mouse button up
Thread.Sleep(15);
/// return mouse
SetCursorPos(oldPoint.X, oldPoint.Y);
}
It's restore game window click on point and minimize game window.
It's works good, but just when i'm not moving mouse...
I search something else. I want to click mouse without moving it for real. It's even possible do it in game? I don't have any handle for button i want to click because it's a game...
P.S
Sorry for my english.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…