Created
April 22, 2020 12:41
-
-
Save MwBakker/42e5a9c3f30a883555dd5deb5c4a79ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<bool> PerformTextualInputAsync(string text) | |
{ | |
UIElement focusedControl = Keyboard.FocusedElement as UIElement; | |
if (focusedControl != null) | |
{ | |
text = text.ToUpper(System.Globalization.CultureInfo.CurrentCulture); | |
string[] textArray = text.ToCharArray().Select(c => c.ToString()).ToArray(); | |
if (Keyboard.PrimaryDevice.ActiveSource != null) | |
{ | |
// deadlock | |
await Task.Run(() => PerformAllKeyBoardInput(textArray)); | |
// check if value is set | |
if (((TextBox)focusedControl).Text != null) | |
{ | |
return ((TextBox)focusedControl).Text.Equals(text) ? true : false; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
else | |
{ | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void PerformAllKeyBoardInput(string[] textArray) | |
{ | |
System.Windows.Forms.Keys key; | |
foreach (string element in textArray) | |
{ | |
Enum.TryParse(element, out key); | |
PressKey(key); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment