注意:我对此很陌生,所以如果我犯了愚蠢的错误,我会道歉,我正在学习!:D
所以基本上我想在按住鼠标左键的同时执行一个动作,在我的情况下,我希望程序执行一个左键,而这是真的。我做了以下事情:
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention =
CallingConvention.StdCall)]
public static extern void mouse_event(int dwFlags, int dx, int dy, int
cButtons, int dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x0002;
private const int MOUSEEVENTF_LEFTUP = 0x0004;
bool isDown = false;
private void mouseMoveEventHandler(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isDown = true;
}
else
{
isDown = false;
}
}
//send click
public void send()
{
while (isDown == true){
int dly = 100;
txtDly.Text = dly.ToString();
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
System.Threading.Thread.Sleep(dly);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
}
这目前对我不起作用,点击事件是否仅在我在表单上时发生?或者它会在我的计算机上的任何地方执行点击?
感谢您的帮助,如果这是一个愚蠢的问题,我们深表歉意。