Keyboard sequence shortcuts for menu
.net, c#, keyboard-shortcuts, menu, visual-studio
Solution
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.
- Using the ShortCutKeyDisplayString property to show the custom shortcut next to the menu item.
Problem
I wish to have a sequence shortcut for the program I'm developing (in C# .net) to access various buttons in the menu system. For example: Ctrl + W, O First, the user would press Ctrl + W, followed by O Visual studio uses this method for quite a few of it's menu shortcuts. When I am editing a menu however, I'm limited to only one shortcut Ctrl + W or just O, I cannot sequence them. Is this possible to do with the existing framework?