模拟鼠标点击 [英] Simulating Mouse a Click
本文介绍了模拟鼠标点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好。我正在使用Windows窗体处理我的项目,需要模拟鼠标单击。我从文本框中获取坐标,按下按钮后必须进行双击,但不幸的是我没有点击。谁能说出原因?这是一个代码:
[DllImport( user32 .dll,CharSet = CharSet.Auto,CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event( uint dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
private const int MOUSEEVENT_LEFTDOWN = 0x0002;
private const int MOUSEEVENTF_LEFTUP = 0x0004;
private const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
private const int MOUSEEVENTF_RIGHTUP = 0x0010;
private const int MOUSEEVENTF_ABSOLUTE = 0x8000;
private void button2_Click( object sender,EventArgs e)
{
int x = Convert.ToInt32(textBox1.Text);
int y = Convert.ToInt32(textBox2.Text);
mouse_event(MOUSEEVENT_LEFTDOWN,x,y, 0 , 0 );
mouse_event(MOUSEEVENTF_LEFTUP,x,y, 0 , 0 );
mouse_event(MOUSEEVENT_LEFTDOWN,x,y, 0 , 0 );
mouse_event(MOUSEEVENTF_LEFTUP,x,y, 0 , 0 );
}
解决方案
我会改变
mouse_event(MOUSEEVENT_LEFTDOWN,x,y,0,0);
to
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTFLEFTUP,x,y, 0 , 0 );
按此; 如何在c#中模拟鼠标点击 [ ^
Hello everyone. I am working on my project in Windows Form and need to simulate a Mouse Click. I get coordinates from textbox and after pressing button it must make Double Click but unfortunately I it isn't making Click. Can anyone say the reason ? Here is a code :
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
private const int MOUSEEVENT_LEFTDOWN = 0x0002;
private const int MOUSEEVENTF_LEFTUP = 0x0004;
private const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
private const int MOUSEEVENTF_RIGHTUP = 0x0010;
private const int MOUSEEVENTF_ABSOLUTE = 0x8000;
private void button2_Click(object sender, EventArgs e)
{
int x = Convert.ToInt32(textBox1.Text);
int y = Convert.ToInt32(textBox2.Text);
mouse_event(MOUSEEVENT_LEFTDOWN, x, y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
mouse_event(MOUSEEVENT_LEFTDOWN, x, y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
}
解决方案
I would change
mouse_event(MOUSEEVENT_LEFTDOWN, x, y, 0, 0);
to
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTFLEFTUP, x, y,0,0);
As per this; how to simulate a mouse click in c#[^]
这篇关于模拟鼠标点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文