MFC - 将MouseMove发送到Unity应用程序

时间:2014-07-10 16:08:40

标签: c++ mfc unity3d mousemove postmessage

我想将MouseMove命令发送到使用MFC(C ++)在Unity中编写的应用程序。基本上,我发送鼠标点击,它的效果非常好。见代码:

HWND window = GetCurrentTargetHandle();
PostMessage(window, WM_LBUTTONDOWN, MK_LBUTTON, 0);
PostMessage(window, WM_LBUTTONUP, MK_LBUTTON, 0);

现在,我想发送鼠标移动,以使视图发生变化。例如,如果我移动我的物理鼠标,好吧,它可以工作。但是,如果我尝试将MouseMove发送到Unity窗口,它什么都不做。

我试过了:

INPUT input;
::ZeroMemory(&input, sizeof(INPUT));
input.type = INPUT_MOUSE;
input.mi.dx = x;
input.mi.dy = current_y;
input.mi.dwFlags = (MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE);
::SendInput(1, &input, sizeof(INPUT));

此外:

POINT lp;
GetCursorPos(&lp);
::SendMessage(window, MOUSEEVENTF_MOVE, MAKEWPARAM(x, lp.y), MAKELPARAM(x, lp.y));

有人知道我应该做什么吗?

感谢。

0 个答案:

没有答案