如何在C#中的窗口中检测Ctrl + S?我的EventArgs没有`e.Modifiers`

NSo*_*uth 0 c# windows wpf keyboard-shortcuts winforms

这是我的第一个C#(和第一个Windows)应用程序.我想回应一个多键命令,但无法弄清楚如何.Web上的示例使用e.Modifiers,e.Controloverride bool ProcessCmdKey,在我的IDE中没有出现任何选项.我的主要课是一个System.Windows.Window,问题是什么?我一直在读Forms- 我是否利用这个?

这是我的班级标题信息.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
using System.Text;
using System.IO;
using System.Configuration;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.WindowsAPICodePack.Dialogs;
//using System.Windows.Forms.
using Winforms = System.Windows.Forms;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Runtime.Serialization.Formatters.Binary;


namespace ContractCutter
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
...
Run Code Online (Sandbox Code Playgroud)

这就是我尝试做事的地方.我也只有Key课,不是Keys.

void CutContractKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.LeftCtrl)
                stuff;
        }
Run Code Online (Sandbox Code Playgroud)

Car*_*ras 5

你可以用这个:

private void CutContractKeyDown(object sender, KeyEventArgs e)
{
      if (e.Key == Key.S && Keyboard.Modifiers == ModifierKeys.Control)
     {
       MessageBox.Show("CTRL + S");
     }
}
Run Code Online (Sandbox Code Playgroud)