How to use keystrokes, e.g. SHIFT + RETURN, using TestStack library in C#

266 views Asked by At

I need to automate some repetive tasks performed in an application installed in my machine. I'm coding in C# and using the library TestStack.White I can key in keyboard inputs like SHIFT or RETURN but I can“t figure out how to send a key combo. I must send SHIFT+RETURN but this keystroke is not available in TestStack.White as far as I know. How to do it? Maybe it is easier using Windows.Forms.SendKeys... Thank you in advance.

ts_ui_items.TextBox textBox = characteristics_window.Get(ts_ui_items.Finders.SearchCriteria.ByClassName("Edit"));

textBox.Text = "something";

ts.InputDevices.Keyboard.Instance.HoldKey(ts.WindowsAPI.KeyboardInput.SpecialKeys.SHIFT); 

textBox.KeyIn(ts.WindowsAPI.KeyboardInput.SpecialKeys.RETURN); 

ts.InputDevices.Keyboard.Instance.LeaveKey(ts.WindowsAPI.KeyboardInput.SpecialKeys.SHIFT);

textBox.Text = "nice";

This piece of code outputs a text in the application's window in its text box like:

something

nice

This is what I tried and it kind of worked but I think this is not the optimal solution....

0

There are 0 answers