/// <summary> /// Types the specified text. /// </summary> /// <param name="text">The text to type.</param> public static void Type(string text) { foreach (char c in text) { // We get the vKey value for the character via a Win32 API. We then use bit masks to pull the // upper and lower bytes to get the shift state and key information. We then use WPF KeyInterop // to go from the vKey key info into a System.Windows.Input.Key data structure. This work is // necessary because Key doesn't distinguish between upper and lower case, so we have to wrap // the key type inside a shift press/release if necessary. int vKeyValue = MySendKeys.VkKeyScan(c); bool keyIsShifted = (vKeyValue & MySendKeys.VKeyShiftMask) == MySendKeys.VKeyShiftMask; Key key = KeyInterop.KeyFromVirtualKey(vKeyValue & MySendKeys.VKeyCharMask); if (keyIsShifted) { Type(key, new Key[] { Key.LeftShift }); } else { Type(key); } } }