加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – InputSimulator不模拟鼠标点击

发布时间:2020-12-16 01:57:18 所属栏目:百科 来源:网络整理
导读:我正在使用InputSimulator来模拟按键和鼠标点击.到目前为止,我测试的每个键都有效,除了鼠标按钮.我发这样的话: private void button2_Click(object sender,EventArgs e) //In this example I am trying to simulate the left mouse button { System.Threadi
我正在使用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);
    }

但没有任何反应.我做错了吗?

图书馆:InputSimulator

解决方法

我不太了解InputStimulator但是根据 this post.你可以使用刺激鼠标点击;

[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);
      mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP,0);

记得使用System.Runtime.InteropService添加;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读