Basically I have run-time loaded class that looks like this:
[Plugin("Plugin name")]
class PluginActions
{
[Action("Flip Normals")
public void FlipNormals()
{
// code ....
}
[Action("Export .X object")
public void ExportX()
{
// code ....
}
}
This basically adds buttons to the form with the onClick eventhandlers set up.
Now I would like to specify HOTKEYs in the same style using attributes:
[Plugin("Plugin name")]
class PluginActions
{
[Action("Flip Normals", Hotkey = "Ctrl+N")
public void FlipNormals()
{
// code ....
}
[Action("Export .X object", Hotkey = "Ctrl+E")
public void ExportX()
{
// code ....
}
}
The question is, how to represent and capture the hotkeys? As strings? Is there perhaps a class for that?
void Form_KeyDown(object sender, KeyEventArgs e)
{
// reflection magic ...
foreach(var action in actionAttributes)
{
string action_hotkey = action.hotkey;
/**** How to match KeyEventArgs against action_hotkey? ****/
}
}
Is there a .net helper class for dealing with hotkeys?
Or do i have to roll out my own hotkey class of some kind?
What is the correct approach here?
There is the Keys enumeration in the System.Windows.Forms namespace. Then for hotkey Ctrl+A you can write something like this: