我有一個用Directx編寫的遊戲(不是我的遊戲)。遊戲窗口不活動(不是最小化,只是在其他窗口的後面,但如果可能的話,它也可以最小化)。如何在Directx遊戲中模擬鼠標點擊
我想模擬鼠標點擊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);
}
這點上恢復遊戲窗口點擊最小化遊戲窗口。
它的作品不錯,但只是當我不動鼠標...
我尋找別的東西。我想單擊鼠標而不移動它爲真實。甚至有可能在遊戲中做到這一點?我沒有任何按鈕我想點擊,因爲它是一個遊戲...
P.S 對不起,我的英語。
沒有人在這場比賽中扮演:d,我想只要按PLAY鍵:d,所以它不是一個機器人,我只是想知道我該怎麼做,如果它甚至可能。這場比賽是冠軍決鬥,我的技能太低(現在)寫一個人工智能或神經網絡:P – Kaki
我推薦'SendMessage'而不是試圖控制其他窗口和鼠標。 – chris
有點失敗:D我正在嘗試SendMesseage,但沒有效果。 Spy ++沒有向我展示任何東西,因爲我使用的是64位版本的Spy ++,32位版本可以正常工作。 – Kaki