简体   繁体   English

如何在WinForm应用程序中检测Ctrl - Forward Slash

[英]How to detect Ctrl - Forward Slash in WinForm app

Below is the code for Ctrl + F (from another SO post). 下面是Ctrl + F的代码(来自另一个SO帖子)。 But how do you detect a Ctrl + ForwardSlash ? 但是如何检测Ctrl + ForwardSlash or Ctrl + / (note: divide does not work) 或者Ctrl + / (注意:除法不起作用)

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (1 == 1) //keyData == (Keys.Control | Keys.F))
        {
            MessageBox.Show("What the Ctrl+F?");
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }

Divide should work fine. 划分应该工作正常。

For Ctrl + \\ : 对于Ctrl + \\

if (keyData == (Keys.Control | Keys.OemPipe) )

For Ctrl + / : 对于Ctrl + /

if (keyData == (Keys.Control | Keys.OemQuestion) )

For some reason (not sure why), when you trap Ctrl + these keys, they're mapping to the "shifted" keymappings. 出于某种原因(不确定原因),当您捕获Ctrl +这些键时,它们将映射到“已移位”键映射。


Edit: 编辑:

One trick for finding this, or any other key. 找到这个或任何其他密钥的一个技巧。 Set a breakpoint on any line in that method, and look at the keyData value when you press the key you're trying to trap. 在该方法的任何一行上设置断点,并在按下要尝试陷阱的键时查看keyData值。 I recommend doing this without hitting control. 我建议这样做而不要控制。 You can then use reflector to get all of the specific values for Keys , and find the "key" with the appropriate value. 然后,您可以使用反射器获取Keys所有特定值,并找到具有适当值的“键”。

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

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