如何在c#中模拟鼠标拖动并获取鼠标点击位置
问题描述:
实际上这是两个问题,但这些都与鼠标操作有关。
我想编写一个可以模拟鼠标操作的小工具,例如将文件拖到新位置。 br />
但我不知道如何获得鼠标点击位置,因为我想记录鼠标操作。我不知道如何模拟鼠标拖动。任何人都可以给我一些想法。非常感谢。
P.S.对于鼠标拖动,我尝试了这种方法,但它不起作用:
In fact this is two question, but those is all about mouse operate.
I want to code a small tool which can simulate mouse operates, such as drag a file to a new position.
But I don't know how to get the mouse click position, as I want to record the mouse operation. and I don't know how to simulate mouse drag. Can anyone give me some ideas. Thanks very much.
P.S. For mouse drag, I tried this method but it won't work:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
public const int MOUSEEVENTF_LEFTDOWN = 0x2;
public const int MOUSEEVENTF_LEFTUP = 0x4;
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Cursor.Position = new System.Drawing.Point(x, y); //X,Y is the new position
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);