我有一个用 Directx 编写的游戏(不是我的,它是 mmo 游戏)。游戏窗口未激活(未最小化,只是位于其他窗口的后面,但如果可能,也可以将其最小化)。
我想模拟鼠标点击 x,y 位置。当我在游戏中单击时,Spy++ 不会在消息中显示任何内容。
现在我这样做了:
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);
}
它是恢复游戏窗口点击点并最小化游戏窗口。
它很好用,但就在我不移动鼠标的时候......
我搜索别的东西。我想点击鼠标而不真正移动它。甚至有可能在游戏中做到这一点?我没有要单击的按钮的句柄,因为它是游戏...
PS对不起我的英语。