The inputs expected by SendKeys
(.SendWait
or .Send
) do not always match the name of the key being pressed. You can find a list with all the "special keys" in this link. You have to create a way to convert the names in comboKey
into the format expected by SendKeys
. An easy and effective solution is relying on a Dictionary
. Sample code:
Dictionary<string, string> dict = new Dictionary<string, string>();
dict.Add("a", "a");
dict.Add("backspace", "{BACKSPACE}");
dict.Add("break", "{BREAK}");
//replace the keys (e.g., "backspace" or "break") with the exact name (in lower caps) you are using in comboKey
//etc.
You need to convert SendKeys.SendWait(selectedKey.ToString());
into:
SendKeys.SendWait(dict[selectedKey.ToString()]);