Page 1 of 2

hot key support

Posted: Tue Mar 31, 2009 11:22 pm
by chris
How do you press hot keys like alt+f? I noticed a post that mentioned you could use {ALTDOWN} to hole the alt key down, but that doesn't seem to work in version 2. Any suggestions?
Thanks.

Posted: Tue Mar 31, 2009 11:28 pm
by Ciege
In my c# code I use the following to issue an Alt-F O to trigger the File -> Open menu...

Keyboard.Press("{ALT}fo");

Posted: Wed Apr 01, 2009 12:16 am
by chris
Thanks for the quick reply. For some reason, that doesn't seem to work for me. I am trying to access a text box and type something in it, so I thought it might be easier to just use the hot key for the text box and then start typing since the only thing different about the text boxes are the controlID. Is the controlID going to be the same every time on every machine?
Thanks.

Posted: Wed Apr 01, 2009 12:32 am
by Ciege
I guess that kind of depends. What does the spy tool tell you?
Can you click and set focus to the text box based on it's name or a unique ID?
Is the text box getting focus before you start typing in it?

The Keyboard.Press method should be issuing the keys you tell it to. What is you code for setting focus to the text box before you start typing?

Posted: Wed Apr 01, 2009 10:13 am
by Support Team
The code for the Keyboard.Press should look like the following:

Code: Select all

Keyboard.Press("{Alt down}{fkey}{Alt up}");
// or
Keyboard.Down(Keys.LMenu);
Keyboard.Press(Keys.F);
Keyboard.Up(Keys.LMenu);
Please consult the API documentation of the Keyboard.Press method for more information on the valid syntax for that method.
Usually, you can also try to record your keystrokes using the RanorexRecorder, however, in this special case (combinations of Alt/Ctrl and another key) the Recorder in V2.0 generates a buggy string. This error will be fixed in the upcoming V2.0.2.

Regards,
Alex
Ranorex Support Team

Posted: Wed Apr 01, 2009 5:41 pm
by Ciege
Are you suggesting that what I am using should not work? It does...

Code: Select all

Keyboard.Press("{ALT}fo");
Visiting the API Documentation for the Keyboard.Press method in turn takes you to the MSDN Keys Enumeration documentation http://msdn.microsoft.com/en-us/library ... .keys.aspx.

This documentation clearly states that the Alt key modified is {Alt}. So it would appear that we are both right, but the method you describe with the {Alt down} and {Alt up} is just a longer way of doing it.

Posted: Wed Apr 01, 2009 7:02 pm
by chris
Thanks for all the suggestions. I did the following:

Code: Select all

textBox.EnsureVisible();
Keyboard.Press("{Alt down}{fkey}{Alt up}");
That works now. Thanks for all the quick responses.

Posted: Thu Apr 02, 2009 8:29 am
by Support Team
Ciege wrote:Are you suggesting that what I am using should not work? It does...

Code: Select all

Keyboard.Press("{ALT}fo");
I bet your code works as well for most shortcuts, but sometimes you need to hold down the ALT key while pressing the shortcut key. Your code means:
- press the ALT key
- release the ALT key
- press and release the F key
- press and release the O key

The code I posted holds down the ALT key while pressing/releasing the F key. It's just two ways to invoke shortcuts :-)

Regards,
Alex
Ranorex Support Team

Posted: Thu Apr 02, 2009 5:33 pm
by Ciege
Support Team wrote:Your code means:
- press the ALT key
- release the ALT key
- press and release the F key
- press and release the O key
Hmmm, interesting. If that what it truly means then I wonder why it works like Alt+F. If it was just doing Alt-down, Alt-Up, F I would expect that the file menu in the AUT would not actually open since it requires an Alt+F.
Regardless, I'll keep this info in mind incase it comes back to haunt me in the future.

Posted: Fri Apr 03, 2009 8:24 am
by Support Team
If you press (and release) ALT, in most applications the focus moves to the menu and the following character determines the menu that is opened. However, with some applications that's not true and you need to hold down the ALT key while pressing the right character. Usually, the second way (holding down ALT while pressing character) is the safer one that should work almost evertime :-)

Regards,
Alex
Ranorex Support Team

Posted: Fri Apr 03, 2009 4:13 pm
by Ciege
I see, and yes you are correct. I bow to your greatness! Thanks for describing it for me.

Re: hot key support

Posted: Wed Jul 27, 2011 7:27 pm
by omayer
what will be the shortcut key for {TAB}
Thank you
Beginner

Re: hot key support

Posted: Wed Jul 27, 2011 8:03 pm
by Ciege
omayer wrote:what will be the shortcut key for {TAB}
Thank you
Beginner
What do you mean by shortcut key for {TAB}? Do you mean, how do you type tab? If yes... use

Code: Select all

{TAB}

Re: hot key support

Posted: Wed Sep 19, 2012 6:18 pm
by omayer
am i missing something - trying to use ctrl an f to popup the find box using

Keyboard.Press("{Ctrl down}{fkey}");

but getting error - 'ctrl' is not a valid member of the System.Windows.Forms.Keys enumeration.
Thank you in advance-

Re: hot key support

Posted: Wed Sep 19, 2012 6:30 pm
by Ciege
A quick google of "System.Windows.Forms.Keys" reveals this lik: http://msdn.microsoft.com/en-us/library ... .keys.aspx