[英]Simulating mouse events? C#
I'm trying to create a windows forms program which makes the computer act as if I pressed a mouse-button. 我正在尝试创建一个Windows窗体程序,使计算机就像按下鼠标按钮一样。 I want to control the events manually (timing is not decided in advance) and it needs to possible to press and hold, so the mouse-button release should be a separate event. 我想手动控制事件(时间不提前决定),并且需要按住,因此鼠标按钮释放应该是一个单独的事件。
The following information should not change the code, just help you further understand my situation: 以下信息不应更改代码,只是帮助您进一步了解我的情况:
Thanks in advance! 提前致谢! :D :d
I simulate mouse events like this 我模拟像这样的鼠标事件
[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;
usage example: 用法示例:
public static void leftClick()
{
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.