I'm trying to implement LBUTTONDOWN->MOUSEMOVE->WM_LBUTTONUP using winapi in outfocus. But the "MouseButtons" information doesn't come.
I want to simulate the same mouse click and move using winapi.
I created a winform application to make sure winapi works. This form Event monitors mouse and keyboard input.
Using
SendMessage LBUTTONDOWN-> MOUSEMOVE-> WM_LBUTTONUP
message has been sent.
But my code doesn't give the button information during MOUSEMOVE.
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam);
Here is my code.
int x = 0;
int y = 0;
IntPtr lparam = IntPtr.Zero;
x = 160;
y = 500;
lparam = new IntPtr(x | (y << 16));
SendMessage(hwnd_child, WM_LBUTTONDOWN, (int)0x0, lparam);
Thread.Sleep(3000);
//이벤트
for (int i = 0; i < 100; ++i)
{
//일반
x = 160;
y = 500 - i;
lparam = new IntPtr(x | (y << 16));
SendMessage(hwnd_child, WM_MOUSEMOVE, 0, lparam);
//Thread.Sleep(10);
}
x = 160;
y = 500 - 100;
lparam = new IntPtr(x | (y << 16));
SendMessage(hwnd_child, WM_LBUTTONUP, (int)0x0, lparam);
Existing result (See Previous image)
2019-09-02 Added
I modified the code in the way of the answer.
I checked the log through spy++.
Modified code
//SendMessage -> PostMessage
PostMessage(hwnd_child, WM_MOUSEMOVE, MK_LBUTTON, lparam);
Desired result.
Log obtained by dragging the mouse directly.
test program code
private void FrmMain_MouseMove(object sender, MouseEventArgs e)
{
if (this.m_bMouseMoveEnabled == true)
{
this.SendLog("MouseMove"
, string.Format("Btn:{0}, X:{1}, Y:{2}"
, e.Button
, e.X
, e.Y));
}
}
2022-05-04 Update
I have created several test programs.
And I found the cause.
The 'MOUSEMOVE' information of 'winapi' appears to be that of a physical mouse.
I have "MouseButtons" when I hold down the physics mouse.