How to use CONTROL-Key in Ranorex.PressKeys?

Ranorex Studio, Spy, Recorder, and Driver.
BCTest
Posts: 127
Joined: Tue Jun 03, 2014 10:15 am
Location: Hamburg, Germany

How to use CONTROL-Key in Ranorex.PressKeys?

Post by BCTest » Thu Sep 01, 2016 12:16 pm

Hello,

just a simple question: how to use PressKeys for a sequence with Ctrl-Keys?

Ranorex 6.0.1 works fine when using Keyborad.Press as in function PressCtrlH_Alt1 defined:
Keyboard.Press(System.Windows.Forms.Keys.H | System.Windows.Forms.Keys.Control, Keyboard.DefaultScanCode, Keyboard.DefaultKeyPressTime, 1, true);
But I wonder why my simple test fails when using PressKeys (with a sequence recorded by Ranorex Keystroke Recording) as in function PressCtrlH_Alt2 defined:
repo.Editor.Self.PressKeys("{LControlKey down}h{LControlKey up}");
The same questions belongs to the Key-Functions:
Key Shortcut works, Key Sequence (created by internal Keystroke Recording) doesn't works: Why?
PressKey.png
I attached a simple demo-project:
* Open Windows-Editor
* Type some text
* Press Ctrl+H in different ways
* Close Windows-Editor
PressKey.zip
How do I have to change the non-working calls to work properly?
You do not have the required permissions to view the files attached to this post.

User avatar
RobinHood42
Posts: 324
Joined: Fri Jan 09, 2015 3:24 pm

Re: How to use CONTROL-Key in Ranorex.PressKeys?

Post by RobinHood42 » Fri Sep 02, 2016 9:54 am

Hi BCTest,

You could use the following key sequence:
KeySequence.png
But why don't you just use the "KeyShortcut()"-action? :shock:

Cheers,
Robin
You do not have the required permissions to view the files attached to this post.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to use CONTROL-Key in Ranorex.PressKeys?

Post by krstcs » Fri Sep 02, 2016 3:20 pm

Agree with Robin. If all you need is the key shortcut, then use KeyShortcut(). That's what it's there for.


However, you do have to send the "{LControlKey up}" stroke at some point after what Robin wrote, or the control key will be held until it is sent or the test stops. What you had originally should be working, but you can change the alpha key to what Robin has if you want, but that is a lot of work to just do what KeyShortcut does anyway...
Shortcuts usually aren't...

BCTest
Posts: 127
Joined: Tue Jun 03, 2014 10:15 am
Location: Hamburg, Germany

Re: How to use CONTROL-Key in Ranorex.PressKeys?

Post by BCTest » Thu Sep 22, 2016 1:36 pm

Hi,

thanks for the answers - now I got it.

I wanted to use <code>PressKey</code> in my code not the simple recording-script so I finally used
repo.Element.PressKeys("{ControlKey down}{HKey}{ControlKey up}")
to send CTRL+H. And it works!

Thanks,
Thomas.