3

我正在使用 InputSimulator 来模拟按键和鼠标点击。到目前为止,我测试过的每个键都有效,除了鼠标按钮。我这样发送它们:

private void button2_Click(object sender, EventArgs e) //In this example I am trying to simulate the left mouse button
    {
        System.Threading.Thread.Sleep(2000); 
        InputSimulator.SimulateKeyPress(VirtualKeyCode.LBUTTON);
    }

但什么也没有发生。我做错什么了吗?

库:输入模拟器

4

2 回答 2

6

最新版本的 InputSimulator 支持鼠标事件。以下是如何使用它:

var sim = new InputSimulator();
sim.Mouse.LeftButtonClick();

请注意,二进制下载已过时,因此您必须从源代码构建库。

于 2013-11-29T23:09:18.573 回答
3

我不太了解,InputStimulator但根据这篇文章。您可以使用刺激鼠标点击;

      [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 MOUSEEVENTF_ABSOLUTE = 0x8000;
      private const int MOUSEEVENTF_LEFTDOWN = 0x0002;
      private const int MOUSEEVENTF_LEFTUP = 0x0004;
      private const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
      private const int MOUSEEVENTF_MIDDLEUP = 0x0040;
      private const int MOUSEEVENTF_MOVE = 0x0001;
      private const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
      private const int MOUSEEVENTF_RIGHTUP = 0x0010;
      private const int MOUSEEVENTF_WHEEL = 0x0800;
      private const int MOUSEEVENTF_XDOWN = 0x0080;
      private const int MOUSEEVENTF_XUP = 0x0100;

      //.................................
      //In your own function:

      int X = 1220;
      int Y = 13;
      mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, X, Y, 0, 0);
      mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);

记得添加using System.Runtime.InteropService;

于 2013-09-20T16:47:18.357 回答