In my initial days, I have struggled lot to simulate keyboard inputs. To simulate keyboard inputs in CodedUI as easy as Selenium but sometime it’s hard to find CodedUI solution over the Google. With this post I am trying to break that hardness. So here we go…

if you wanted to send single key…

Keyboard.SendKeys(“{ENTER}”);

or

Keyboard.SendKeys(“{T}”); etc.

If you wanted to send combination keys like ALT+F4.

Keyboard.SendKeys(“{%F4}”);

Code     Key

%          ALT

+           SHIFT

^           CTRL

If you wanted to press particular key 10 times, use below syntax-

//Below syntax will press LEFT ARROW key 10 times.

Keyboard.SendKeys(“{LEFT 10}”);

For more details you can go through this link http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send(v=vs.110).aspx

Advertisements

One thought on “How to simulate keyboard input in C# (CodedUI)

  1. Hi,

    I need to select multiple values from a List Box.
    So, need to hold down the Ctrl button on keyboard, until all the values are selected and then click on OK Button.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s