How to use GetDecodedKeyboardInput method of WinAppDriverUIRecorder.RecordedUiTask class

Best WinAppDriver code snippet using WinAppDriverUIRecorder.RecordedUiTask.GetDecodedKeyboardInput

RecordedUiTask.cs

Source:RecordedUiTask.cs Github

copy

Full Screen

...129 if (this._strDescription == null)130 {131 if (this.UiTaskName == EnumUiTaskName.KeyboardInput)132 {133 var keyboardTaskDescription = GenerateCSCode.GetDecodedKeyboardInput(this.Base64Text, this.CapsLock, this.NumLock, this.ScrollLock);134 StringBuilder sb = new StringBuilder();135 foreach (var strLine in keyboardTaskDescription)136 {137 sb.Append(strLine);138 }139 this._strDescription = $"{this.UiTaskName} VirtualKeys=\"{sb.ToString()}\" CapsLock={this.CapsLock} NumLock={this.NumLock} ScrollLock={this.ScrollLock}";140 }141 else142 {143 // set LeftLocal and TopLocal from _pathNodes.Last()144 if (this.UiTaskName == EnumUiTaskName.Drag || this.UiTaskName == EnumUiTaskName.MouseWheel)145 {146 this._strDescription = $"{this.UiTaskName} on {Tag} \"{this.Name}\" at ({this.LeftLocal},{this.TopLocal}) drag ({this.DeltaX},{this.DeltaY})";147 }148 else149 {150 this._strDescription = $"{this.UiTaskName} on {Tag} \"{this.Name}\" at ({this.LeftLocal},{this.TopLocal})";151 }152 }153 }154 }155 catch (Exception ex)156 {157 AppInsights.LogException("Description", ex.Message);158 }159 if (string.IsNullOrEmpty(this._strDescription))160 {161 this._strDescription = string.Empty;162 }163 return this._strDescription;164 }165 //set is not defined166 }167 public override string ToString()168 {169 return Description;170 }171 public void AppendKeyboardInput(string textToAppend)172 {173 byte[] data1 = Convert.FromBase64String(this.Base64Text);174 byte[] data2 = Convert.FromBase64String(textToAppend);175 byte[] data = new byte[data1.Length + data2.Length];176 data1.CopyTo(data, 0);177 data2.CopyTo(data, data1.Length);178 this.Base64Text = Convert.ToBase64String(data);179 var keyboardTaskDescription = GenerateCSCode.GetDecodedKeyboardInput(this.Base64Text, this.CapsLock, this.NumLock, this.ScrollLock);180 StringBuilder sb = new StringBuilder();181 foreach (var strLine in keyboardTaskDescription)182 {183 sb.Append(strLine);184 }185 this._strDescription = $"{this.UiTaskName} VirtualKeys=\"{sb.ToString()}\" CapsLock={this.CapsLock} NumLock={this.NumLock} ScrollLock={this.ScrollLock}";186 }187 public string GetCSCode(string focusedElemName)188 {189 StringBuilder sb = new StringBuilder();190 sb.AppendLine("// " + this.Description);191 string consoleWriteLine = "Console.WriteLine(\"" + this.Description.Replace("\"", "\\\"") + "\");";192 sb.AppendLine(consoleWriteLine);193 if (this.UiTaskName == EnumUiTaskName.LeftClick)194 {195 sb.AppendLine(GenerateCSCode.LeftClick(this, VariableName));196 }197 else if (this.UiTaskName == EnumUiTaskName.RightClick)198 {199 sb.AppendLine(GenerateCSCode.RightClick(this, VariableName));200 }201 else if (this.UiTaskName == EnumUiTaskName.LeftDblClick)202 {203 sb.AppendLine(GenerateCSCode.DoubleClick(this, VariableName));204 }205 else if (this.UiTaskName == EnumUiTaskName.MouseWheel)206 {207 sb.AppendLine(GenerateCSCode.Wheel(this, VariableName));208 }209 else if (this.UiTaskName == EnumUiTaskName.KeyboardInput)210 {211 sb.AppendLine(GenerateCSCode.SendKeys(this, focusedElemName));212 }213 return sb.ToString();214 }215 public void ChangeClickToDoubleClick()216 {217 this.UiTaskName = EnumUiTaskName.LeftDblClick;218 this._strDescription = null;219 }220 public void DragComplete(int deltaX, int deltaY)221 {222 this.DeltaX = deltaX;223 this.DeltaY = deltaY;224 this.UiTaskName = EnumUiTaskName.Drag;225 this._strDescription = null;226 }227 public void UpdateWheelData(int delta)228 {229 this.DeltaX += 1;230 this.DeltaY += delta;231 this._strDescription = null;232 }233 }234 class GenerateCSCode235 {236 public static string GetCodeBlock(RecordedUiTask uiTask, string elemName, string uiActionLine)237 {238 var xpath = "xpath_" + elemName;239 elemName = "winElem_" + elemName;240 string codeBlock = $"string {xpath} = {uiTask.GetXPath(true)};\n" +241 $"var {elemName} = desktopSession.FindElementByAbsoluteXPath({xpath});\n" +242 $"if ({elemName} != null)\n" +243 "{\n" +244 "CODEBLOCK" +245 "}\n" +246 "else\n" +247 "{\n" +248 " Console.WriteLine($\"Failed to find element using xpath: {" + $"{xpath}" + "}\");\n" +249 " return;\n" +250 "}\n";251 return codeBlock.Replace("CODEBLOCK", uiActionLine);252 }253 public static string LeftClick(RecordedUiTask uiTask, string elemName)254 {255 string codeLine = $" winElem_{elemName}.Click();\n";256 return GetCodeBlock(uiTask, elemName, codeLine);257 }258 public static string DoubleClick(RecordedUiTask uiTask, string elemName)259 {260 string codeLine = $" desktopSession.DesktopSessionElement.Mouse.MouseMove(winElem_{elemName}.Coordinates);\n" +261 $" desktopSession.DesktopSessionElement.Mouse.DoubleClick(null);\n";262 return GetCodeBlock(uiTask, elemName, codeLine);263 }264 public static string RightClick(RecordedUiTask uiTask, string elemName)265 {266 string codeLine = $" desktopSession.DesktopSessionElement.Mouse.MouseMove(winElem_{elemName}.Coordinates);\n" +267 $" desktopSession.DesktopSessionElement.Mouse.ContextClick(null);\n";268 return GetCodeBlock(uiTask, elemName, codeLine);269 }270 public static string Wheel(RecordedUiTask uiTask, string elemName)271 {272 string codeLine = $" //TODO: Wheel at ({uiTask.Left},{uiTask.Top}) on winElem_{elemName}, Count:{uiTask.DeltaX}, Total Amount:{uiTask.DeltaY}\n";273 return GetCodeBlock(uiTask, elemName, codeLine);274 }275 public static List<string> GetDecodedKeyboardInput(string strBase64, bool bCapsLock, bool bNumLock, bool bScrollLock)276 {277 byte[] data = Convert.FromBase64String(strBase64);278 int i = 0;279 bool shift = false;280 StringBuilder sb = new StringBuilder();281 List<string> lines = new List<string>();282 int nCtrlKeyDown = 0;283 while (i < data.Length / 2)284 {285 int n1 = i * 2;286 int n2 = i * 2 + 1;287 i++;288 bool bIsKeyDown = data[n1] == 0;289 VirtualKeys vk = (VirtualKeys)data[n2];290 char ch = ConstVariables.Vk2char((int)vk, shift || bCapsLock);291 if (bIsKeyDown) //Keydown292 {293 if (char.IsControl(ch))294 {295 nCtrlKeyDown++;296 if (nCtrlKeyDown == 1 && sb.Length > 0)297 {298 lines.Add("\"" + sb.ToString() + "\"");299 sb.Clear();300 }301 string vkStr = vk.ToString();302 string vkSendKey = ConstVariables.Vk2string(vkStr);303 if (nCtrlKeyDown == 1)304 sb.Append("Keys." + vkSendKey);305 else306 sb.Append(" + Keys." + vkSendKey);307 }308 else if (ch != 0)309 {310 string strToAppend = ch.ToString();311 if (ch == '\\')312 {313 strToAppend += "\\";314 }315 if (nCtrlKeyDown > 0)316 {317 sb.Append(" + \"" + strToAppend + "\"");318 }319 else320 {321 sb.Append(strToAppend);322 }323 }324 }325 else //Keyup326 {327 if (char.IsControl(ch))328 {329 nCtrlKeyDown--;330 string vkStr = vk.ToString();331 string vkSendKey = ConstVariables.Vk2string(vkStr);332 if (nCtrlKeyDown == 0)333 {334 lines.Add(sb.ToString() + " + Keys." + vkSendKey);335 sb.Clear();336 }337 else338 {339 sb.Append(" + Keys." + vkSendKey);340 }341 }342 }343 }344 if (sb.Length > 0)345 {346 lines.Add("\"" + sb.ToString() + "\"");347 }348 return lines;349 }350 public static string SendKeys(RecordedUiTask uiTask, string focusedElemeName)351 {352 List<string> lines = GetDecodedKeyboardInput(uiTask.Base64Text, uiTask.CapsLock, uiTask.NumLock, uiTask.ScrollLock);353 StringBuilder sb = new StringBuilder();354 focusedElemeName = "winElem_" + focusedElemeName;355 sb.AppendLine($"System.Threading.Thread.Sleep(100);");356 foreach (string line in lines)357 {358 sb.AppendLine($"{focusedElemeName}.SendKeys({line});");359 }360 return sb.ToString();361 }362 }363}...

Full Screen

Full Screen

GetDecodedKeyboardInput

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using WinAppDriverUIRecorder;7{8 {9 static void Main(string[] args)10 {11 RecordedUiTask task = new RecordedUiTask();12 string input = "abc123";13 string result = task.GetDecodedKeyboardInput(input);14 Console.WriteLine(result);15 Console.ReadLine();16 }17 }18}

Full Screen

Full Screen

GetDecodedKeyboardInput

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using WinAppDriverUIRecorder;7{8 {

Full Screen

Full Screen

GetDecodedKeyboardInput

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using WinAppDriverUIRecorder;7using System.IO;8{9 {10 static void Main(string[] args)11 {12 RecordedUiTask task = new RecordedUiTask();13 task.KeyStroke = "Hello";14 task.KeyCode = 0;15 task.KeyDown = false;16 task.KeyUp = false;17 task.KeyChar = 'H';18 task.KeyModifiers = 0;19 task.KeyLocation = 0;20 task.KeyRepeatCount = 0;21 task.KeyTime = 0;22 task.KeyUnicodeChar = 0;23 task.KeyVirtualKey = 0;24 task.KeyWindowHandle = 0;25 task.KeyWindowX = 0;26 task.KeyWindowY = 0;27 task.KeyWindowWidth = 0;28 task.KeyWindowHeight = 0;29 task.KeyWindowProcessId = 0;30 task.KeyWindowProcessName = null;31 task.KeyWindowClassName = null;32 task.KeyWindowName = null;33 string decode = task.GetDecodedKeyboardInput();34 Console.WriteLine(decode);35 Console.ReadLine();36 }37 }38}39using System;40using System.Collections.Generic;41using System.Linq;42using System.Text;43using System.Threading.Tasks;44using WinAppDriverUIRecorder;45using System.IO;46{47 {48 static void Main(string[] args)49 {50 RecordedUiTask task = new RecordedUiTask();51 task.MouseClick = false;52 task.MouseDoubleClick = false;53 task.MouseDown = false;54 task.MouseMove = false;55 task.MouseUp = false;56 task.MouseWheel = false;57 task.MouseX = 0;58 task.MouseY = 0;59 task.MouseWheelDelta = 0;60 task.MouseClickCount = 0;61 task.MouseWindowHandle = 0;62 task.MouseWindowX = 0;63 task.MouseWindowY = 0;64 task.MouseWindowWidth = 0;65 task.MouseWindowHeight = 0;66 task.MouseWindowProcessId = 0;

Full Screen

Full Screen

GetDecodedKeyboardInput

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using System.Windows.Forms;7using WinAppDriverUIRecorder;8{9 {10 public void Method()11 {12 var task = new RecordedUiTask();13 task.GetDecodedKeyboardInput(new Keys[] { Keys.A, Keys.B, Keys.C, Keys.D });14 }15 }16}17using System;18using System.Collections.Generic;19using System.Linq;20using System.Text;21using System.Threading.Tasks;22using System.Windows.Forms;23using WinAppDriverUIRecorder;24{25 {26 public void Method()27 {28 var task = new RecordedUiTask();29 task.GetDecodedKeyboardInput(new Keys[] { Keys.A, Keys.B, Keys.C, Keys.D, Keys.E, Keys.F, Keys.G });30 }31 }32}33using System;34using System.Collections.Generic;35using System.Linq;36using System.Text;37using System.Threading.Tasks;38using System.Windows.Forms;39using WinAppDriverUIRecorder;40{41 {42 public void Method()43 {44 var task = new RecordedUiTask();45 task.GetDecodedKeyboardInput(new Keys[] { Keys.A, Keys.B, Keys.C, Keys.D, Keys.E, Keys.F, Keys.G, Keys.H, Keys.I, Keys.J, Keys.K, Keys.L, Keys.M });46 }47 }48}49using System;50using System.Collections.Generic;51using System.Linq;52using System.Text;53using System.Threading.Tasks;54using System.Windows.Forms;55using WinAppDriverUIRecorder;56{57 {58 public void Method()59 {60 var task = new RecordedUiTask();61 task.GetDecodedKeyboardInput(new Keys[] { Keys.A, Keys.B, Keys.C, Keys.D, Keys

Full Screen

Full Screen

GetDecodedKeyboardInput

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using WinAppDriverUIRecorder;7{8 {9 static void Main(string[] args)10 {11 string path = @"C:\Users\Public\Documents\WinAppDriverUIRecorder\RecordedUiTasks\RecordedUiTask_2018-10-30_07-09-43_1.txt";12 RecordedUiTask recordedUiTask = RecordedUiTask.Load(path);13 string decodedKeyboardInput = recordedUiTask.GetDecodedKeyboardInput();14 string decodedMouseInput = recordedUiTask.GetDecodedMouseInput();15 string decodedTouchInput = recordedUiTask.GetDecodedTouchInput();16 }17 }18}19using System;20using System.Collections.Generic;21using System.Linq;22using System.Text;23using System.Threading.Tasks;24using WinAppDriverUIRecorder;25{26 {27 static void Main(string[] args)28 {29 string path = @"C:\Users\Public\Documents\WinAppDriverUIRecorder\RecordedUiTasks\RecordedUiTask_2018-10-30_07-09-43_1.txt";30 RecordedUiTask recordedUiTask = RecordedUiTask.Load(path);

Full Screen

Full Screen

GetDecodedKeyboardInput

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using WindowsInput;7using WindowsInput.Native;8using WinAppDriverUIRecorder;9{10 {11 static void Main(string[] args)12 {13 RecordedUiTask recordedTask = new RecordedUiTask();14 recordedTask.Path = "C:\\Users\\srikanth\\Desktop\\test.txt";15 recordedTask.Load();16 string keyboardInput = recordedTask.GetDecodedKeyboardInput();17 Console.WriteLine(keyboardInput);18 Console.ReadLine();19 InputSimulator inputSim = new InputSimulator();20 inputSim.Keyboard.TextEntry(keyboardInput);21 }22 }23}

Full Screen

Full Screen

GetDecodedKeyboardInput

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using WinAppDriverUIRecorder;4{5 {6 static void Main(string[] args)7 {8 RecordedUiTask recordedUiTask = RecordedUiTask.GetRecordedUiTask("recordedtask.json");9 List<string> decodedKeyboardInput = recordedUiTask.GetDecodedKeyboardInput();10 foreach (string keyboardInput in decodedKeyboardInput)11 {12 Console.WriteLine(keyboardInput);13 }14 }15 }16}17using System;18using System.Collections.Generic;19using WinAppDriverUIRecorder;20{21 {22 static void Main(string[] args)23 {24 RecordedUiTask recordedUiTask = RecordedUiTask.GetRecordedUiTask("recordedtask.json");25 List<string> decodedMouseInput = recordedUiTask.GetDecodedMouseInput();26 foreach (string mouseInput in decodedMouseInput)27 {28 Console.WriteLine(mouseInput);29 }30 }31 }32}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run WinAppDriver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful