English 中文(简体)
检测Ctrl+ 进口
原标题:detect Ctrl + Enter

(using WPF) i try to detect when Ctrl + Enter gets hit. so i tried this code:

if (e.Key == Key.Return && (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl))
 {
   //Do Something            
 }

Obviously this is not correct, as it does not work. Could anyone help me out, explaining what the right way should be ?

thanx

最佳回答

缩略语 同一情况下,其价值不能超过一种。

您需要处理使用<代码>KeyEventArgs的其中一个事件,其中你发现诸如<代码>Control和Modifiers等有助于检测组合的特性。

The KeyPress activity, which used KeyPressEventArgs, only don t have sufficient information.


Drat, 您说,妇女论坛 did你。 参看<代码>e.Key板Device.Modifiers。

问题回答

I think you need a SpecialKey Handler. I googled a bit a found a solution here.

根据上述链接的代码,可以解决你的问题:

  void SpecialKeyHandler(object sender, KeyEventArgs e)
{
    // Ctrl + N
    if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.N))
    {
        MessageBox.Show("New");
    }

    // Ctrl + O
    if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.O))
    {
        MessageBox.Show("Open");
    }

    // Ctrl + S
    if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.S))
    {
        MessageBox.Show("Save");
    }

    // Ctrl + Alt + I
    if ((Keyboard.Modifiers == (ModifierKeys.Alt | ModifierKeys.Control)) && (e.Key == Key.I))
    {
        MessageBox.Show("Ctrl + Alt + I");
    }
}
if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Enter)
   if (e.KeyChar == 10)
            {
             ///Code
            }

 if ((Char)e.KeyChar ==  
 )
            {
             ///Code
            }




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签