私は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私の英語でごめんなさい。