locked
How do I send arrow keys using Sendkey? RRS feed

  • Question

  • I need a work around to get to a menu item since I'm not able to get the mouse clicks working. So, I thought I'd trying using the keyboard.

    What I need to do is

    // Press and release the ALT key to bring focus on the first menu item

    Keyboard.PressModifierKeys(this.UIMap.UISwitcherProDesktopWindow1, ModifierKeys.Alt);
    Keyboard.ReleaseModifierKeys(this.UIMap.UISwitcherProDesktopWindow1, ModifierKeys.Alt);

    Now, I need to send the keys right arrow 3 times, down arrow 5 times, and enter

     

    I don't know what to use as a string for the arrow keys and the enter key. The API reference for SendKey (http://msdn.microsoft.com/en-us/library/dd433886%28v=VS.100%29.aspx) only gives me a couple of examples.

    While I'm at it, where is the whole reference map for every key on the keyboard as well? Is this documented somewhere? NumLock? Print Screen? BackSpace?


    Thanks,

    Brandon

    Friday, April 9, 2010 3:50 PM

Answers

All replies

  • Brandon,

    Check out the syntax for SendKeys here:
    http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx

    - J


    arcgadion
    • Marked as answer by Brandon Hoppe Friday, April 9, 2010 3:54 PM
    Friday, April 9, 2010 3:52 PM
  • Brandon,

    Check out the syntax for SendKeys here:
    http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx

    - J


    arcgadion


    Awesome, that's exactly what I was looking for!

     

    Thanks!

    Friday, April 9, 2010 3:53 PM
  • Hmmm...the repeat isn't working like the example says:

     

    To specify repeating keys, use the form {key number}. You must put a space between key and number. For example, {LEFT 42} means press the LEFT ARROW key 42 times; {h 10} means press H 10 times.

     

    I tried doing this:

    Keyboard.SendKeys(this.UIMap.Window, "{RIGHT 3}");

     

    But it doesn't work. I had to do it like:

    Keyboard.SendKeys(this.UIMap.Window, "{RIGHT}");

    Keyboard.SendKeys(this.UIMap.Window, "{RIGHT}");

    Keyboard.SendKeys(this.UIMap.Window, "{RIGHT}");

     

    Brandon

    Friday, April 9, 2010 4:12 PM
  • You can put a for loop and do this.

    The document you are referring is System.Windows.Forms.Keyboard.SendKeys() method and the one you are using is Microsoft.VisualStudio.TestTools.UITesting.Keyboard.SendKeys() and hence things are not working as per doc.

    Thanks.


    http://blogs.msdn.com/gautamg
    Saturday, April 10, 2010 4:41 AM
  • BTW - Why does click on the menu does not work?
    http://blogs.msdn.com/gautamg
    Saturday, April 10, 2010 4:41 AM
  • BTW - Why does click on the menu does not work?
    http://blogs.msdn.com/gautamg

    The menu items are a 3rd party Telerik control, so its giving me issues. I can get it to click the main menu buttons, i.e. File,Help, etc, but I haven't been able to get it to click on one of the drop down menu items. The recorded click just reverts to the first button instance on the main window it finds (the minimize button) and I haven't been able to figure out any search properties to match the menu item button.

    I tried iterating thru all the button instances of the main window to see which number it was, but the buttons in the drop down menus don't come up in that loop.

    I can't do a CUIT crosshair on the menu item since I can't get the drop down menu to appear when I'm controlling the crosshairs.

    Brandon

    Monday, April 12, 2010 4:55 PM
  • You can use CUIT crosshair on your menuitem by opening the CUIT and then Opening the menu item you want to get and then hover the mouse over it. Now you can press Win + I key for CUIT to get the properties of the MenuItem.

    Thanks

    Siddhartha

    Tuesday, April 13, 2010 4:37 AM
    Moderator
  • Siddhartha,

     

    Thanks, I didn't know about that shortcut. That will be helpful. I'll play around with that and see if I can get the menu clicks working.


    Brandon

    Tuesday, April 13, 2010 3:10 PM