【问题标题】:C# hide ctrl key in mouse_eventC# 在 mouse_event 中隐藏 ctrl 键
【发布时间】:2013-10-16 23:01:58
【问题描述】:

当按下 ctrl 键时,我尝试发送mouse-click

我发现接收鼠标点击事件的应用程序将 ctrl 键解释为按下。

在发送鼠标事件之前,我可以对代码中的 ctrlrelease 做什么?

我正在使用mouse_event 发送LeftDown 消息,如果这是一个有用的线索。

谢谢!

【问题讨论】:

    标签: c# winapi mouseevent


    【解决方案1】:

    如果您想阻止默认行为,请从控件中的此覆盖方法返回 true:

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (keyData == Keys.Ctrl)
        {
            //send mouse event
            return true;
        }
    }
    

    【讨论】:

      【解决方案2】:

      在使用 mouse_event 之前尝试使用 keybd_event():

          [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
          public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int extraInfo);
      
          [DllImport("user32.dll")]
          static extern short MapVirtualKey(int wCode, int wMapType);
      
          // ...
              keybd_event((int)Keys.ControlKey, (byte)MapVirtualKey((int)Keys.ControlKey, 0), 2, 0); // Control Up                
              // ... call mouse_event() ...
      

      【讨论】:

        【解决方案3】:

        感谢您的回答。我担心有人会认为我正在使用 WinForms 控件:)

        我发现 Windows 输入模拟器库 (http://inputsimulator.codeplex.com/) 能够满足我的需求。在我发出“鼠标按下”消息之前,我使用它来发送“向上键”消息,一切正常。

        再次感谢您的回答!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-04-15
          • 2017-11-19
          • 2013-12-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-03-24
          相关资源
          最近更新 更多