I've been looking over here, but usually question is other way roud "how to convert virtualkey to char". So I need to ask how to convert char into virtualkeycode?
I can perfectly fine work with F1, Ctrl etc., but can't figure out how to convert A to VK_A etc. in some convenient way.
I'm trying to let external configuration file hold some variables which then have to be used as virtualkeycodes in actual application.
I can recognize pairs like
Alt+F2, Shift+Control+F1 ... etc.
As those are just Enum 0-12 and then VirtualKeyCode.F1 + index
But I can't figure out those
Alt+F, Shift+Control+A ... etc.
I'm probably missing something very straightforward but unfortunately i can't see it.
Thanks
Edit:
Thanks to help from here I'm now able to convert "Ctrl+X" or "Shift-A" into VirtualKeyCode with this bit of code (still more like testing code)
public static void ParseKeys(string text)
{
Key key = 0;
Key mod = 0;
int current = 0;
string[] result;
string[] separators = new string[] { "+", "-" };
result = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
foreach (string entry in result)
{
if (entry.Trim() == Keys.Control.ToString() || entry.Trim() == "Ctrl")
mod = Key.LeftCtrl;
if (entry.Trim() == Keys.Alt.ToString())
mod = Key.LeftAlt;
if (entry.Trim() == Keys.Shift.ToString())
mod = Key.LeftShift;
if (entry.Trim() == Keys.LWin.ToString() && current != result.Length - 1)
mod = Key.LWin;
current++;
}
KeysConverter keyconverter = new KeysConverter();
key = (Key)keyconverter.ConvertFrom(result.GetValue(result.Length - 1));
var vmod = KeyInterop.VirtualKeyFromKey(mod);
System.Diagnostics.Trace.WriteLine((VirtualKeyCode)vmod + " = " + (VirtualKeyCode)key);
}
usage
ParseKeys("Alt+X");
I found out I would need to handle combinations like "Alt+Ctrl+X" or "Ctrl+X+Q" but indeed this code is for A+B combo. Can somebody please suggest some elegant solution to have at the end this:
VirtualKeyCode[] outsequence = { VirtualKeyCode.A , VirtualKeyCode.B, VirtualKeycode.C }
? Thanks!