简体   繁体   English

菜单的键盘顺序快捷键

[英]Keyboard sequence shortcuts for menu

I wish to have a sequence shortcut for the program I'm developing (in C# .net) to access various buttons in the menu system. 我希望为我正在开发的程序(在C#.net中)提供一个序列快捷方式,以访问菜单系统中的各种按钮。

For example: Ctrl + W , O 例如: Ctrl + WO

First, the user would press Ctrl + W , followed by O 首先,用户将按Ctrl + W ,然后按O

Visual studio uses this method for quite a few of it's menu shortcuts. Visual Studio的许多菜单快捷方式都使用此方法。

When I am editing a menu however, I'm limited to only one shortcut Ctrl + W or just O , I cannot sequence them. 但是,在编辑菜单时,只能使用一个快捷键Ctrl + W或仅O ,我无法对它们进行排序。

Is this possible to do with the existing framework? 这可能与现有框架有关吗?

Simply you could do this: 只需执行以下操作即可:

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
  if (previousKeyEvent != null)
  {
    if (previousKeyEvent.Modifiers == Keys.Control && previousKeyEvent.KeyCode == Keys.W && e.KeyCode == Keys.O)
    {
      MessageBox.Show("Ctrl + W then O");
    }
    else
    {
      MessageBox.Show("Not handled");
      previousKeyEvent = null;
    }
  else
    previousKeyEvent = e;
  }
}

Things to consider 要考虑的事情

  • Single key combinations - Handling those without the scope of a previous key event. 单键组合-处理那些没有上一个键事件范围的组合。
  • A label for showing that you are awaiting the user input, just like visual studio. 一个标签,用于显示您正在等待用户输入,就像Visual Studio一样。
  • Using the ShortCutKeyDisplayString property to show the custom shortcut next to the menu item. 使用ShortCutKeyDisplayString属性在菜单项旁边显示自定义快捷方式。

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

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