hot key support

Ask general questions here.
chris
Posts: 17
Joined: Fri Mar 27, 2009 6:10 pm

hot key support

Post by chris » Tue Mar 31, 2009 11:22 pm

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.

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Post by Ciege » Tue Mar 31, 2009 11:28 pm

In my c# code I use the following to issue an Alt-F O to trigger the File -> Open menu...

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

chris
Posts: 17
Joined: Fri Mar 27, 2009 6:10 pm

Post by chris » Wed Apr 01, 2009 12:16 am

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.

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Post by Ciege » Wed Apr 01, 2009 12:32 am

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?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Wed Apr 01, 2009 10:13 am

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

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Post by Ciege » Wed Apr 01, 2009 5:41 pm

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.

chris
Posts: 17
Joined: Fri Mar 27, 2009 6:10 pm

Post by chris » Wed Apr 01, 2009 7:02 pm

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.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Thu Apr 02, 2009 8:29 am

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

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Post by Ciege » Thu Apr 02, 2009 5:33 pm

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.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Fri Apr 03, 2009 8:24 am

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

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Post by Ciege » Fri Apr 03, 2009 4:13 pm

I see, and yes you are correct. I bow to your greatness! Thanks for describing it for me.

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: hot key support

Post by omayer » Wed Jul 27, 2011 7:27 pm

what will be the shortcut key for {TAB}
Thank you
Beginner

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: hot key support

Post by Ciege » Wed Jul 27, 2011 8:03 pm

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}
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: hot key support

Post by omayer » Wed Sep 19, 2012 6:18 pm

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-
Tipu

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: hot key support

Post by Ciege » Wed Sep 19, 2012 6:30 pm

A quick google of "System.Windows.Forms.Keys" reveals this lik: http://msdn.microsoft.com/en-us/library ... .keys.aspx
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...