[英]Save and Export Mouse co-ordinates Visual Studio C#
I am trying to create an application using which i will be able to click and drag the mouse any where inside a frame and the corresponding mouse coordinates should be saved in to a stack or a list and i should be able to export the list onto a database or excel file. 我正在尝试创建一个应用程序,通过该应用程序,我将能够在框架内的任何位置单击并拖动鼠标,并将相应的鼠标坐标保存到堆栈或列表中,并且我应该能够将列表导出到数据库或Excel文件。
At present i am able to retrieve the mouse coordinates using, 目前,我可以使用以下方法检索鼠标坐标,
base.OnMouseMove(e);
x = e.X;
y = e.Y;
toolStripStatusLabelXY.Text = x.ToString();
toolStripStatusLabel1.Text = y.ToString();
Is it possible to do this in a C# win32 form application. 是否可以在C#win32窗体应用程序中执行此操作。
Thankyou 谢谢
Add this reference to code 将此引用添加到代码中
using System.Runtime.InteropServices;
and add this code to your code 并将此代码添加到您的代码中
[DllImport("user32.dll", CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons,uint dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
public void DoLeftMouseClick(int x int y)
{
//this function perfoms left click a position you want
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, x, y, 0, 0);
}
public void DoLeftMouseClick(int x int y)
{
//this function perfoms right click a position you want
mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, x, y, 0, 0);
}
If you want to drag use theese; 如果要拖动,请使用theese;
public void DoLeftMouseClickDown(int x int y)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
}
public void DoLeftMouseClickUp(int x int y)
{
mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
}
public void DoLeftMouseClickDown(int x int y)
{
mouse_event(MOUSEEVENTF_RIGHTDOWN , x, y, 0, 0);
}
public void DoLeftMouseClickUp(int x int y)
{
mouse_event(MOUSEEVENTF_RIGHTUP, x, y, 0, 0);
}
Use theese like this; 像这样使用泰斯语;
DoLeftMouseClickDown(positionToClick.X,positionToClick.Y);
DoLeftMouseClickUp(positionToDrag.X,positionToDrag.Y)
this drags the item which is at positionToClick to positionToDrag 这会将位于positionToClick的项目拖动到positionToDrag
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.