[英]mouse_event vs real mouse event
如果有區別:
Edit1:為@Marco Forberg添加了代碼示例。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
Button button;
private void Form1_Load(object sender, EventArgs e)
{
button = new Button();
button.Text = "Click";
button.Location = new Point(50, 50);
button.Size = new System.Drawing.Size(100, 20);
button.Click += button_Click;
Controls.Add(button);
Button simulate = new Button();
simulate.Text = "Simulate";
simulate.Location = new Point(50, 100);
simulate.Size = new System.Drawing.Size(100, 20);
simulate.Click += simulate_Click;
Controls.Add(simulate);
}
void button_Click(object sender, EventArgs e)
{
Console.WriteLine(sender);
}
void simulate_Click(object sender, EventArgs e)
{
Point location = button.PointToScreen(Point.Empty);
Cursor.Position = new Point(location.X + (button.Width / 2), location.Y + (button.Height / 2));
mouse_event(0x02 | 0x04, 0, 0, 0, 0);
}
}
如果創建適當的事件參數,則沒有任何區別。 從“機器”中找出事件的唯一方法是分析時刻。
@ Garath, MSLLHOOKSTRUCT包含一個LLMHF_INJECTED
標志,當事件來自對mouse_event
函數的調用時,將設置該標志。
您可以使用SetWindowsHookEx
檢索此信息,如我在此處所述 。
實際單擊控件和對鼠標事件處理程序的編程調用之間的區別應該是sender
參數。
對於真正的鼠標單擊,您會收到作為發送者被單擊的控件。 以編程方式調用事件處理程序時,您應該提供明智的發送者
我也在嘗試在C#中執行此操作,但是在注入的C#dll中托管了clr。 我的一個朋友建議閱讀這篇文章http://pastebin.com/rj4YcW4C
我嘗試過mouse_event,PostMessage,SendMessage,SendInput和Cursor.Position。 所有人都忽略了,但我相信這篇文章有我們都在尋求的答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.