繁体   English   中英

C#在mouse_event中隐藏ctrl键

[英]C# hide ctrl key in mouse_event

我遇到一种情况,当按下ctrl键时,我试图发送mouse-click

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

发送鼠标事件之前,我该怎么做才能在代码中release ctrl键?

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

谢谢!

如果要防止默认行为,请从控件中此重写的方法返回true:

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

在使用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() ...

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

我发现Windows输入模拟器库( http://inputsimulator.codeplex.com/ )可以为我提供所需的信息。 在执行“鼠标下移”消息之前,我用它来发送“ key up”消息,并且一切正常。

再次感谢您的回答!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM