How to press a key(Keyboard.Press) intstead of a click

Ask general questions here.
ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

How to press a key(Keyboard.Press) intstead of a click

Post by ejji09 » Mon Nov 16, 2015 3:34 pm

Hi,

I want to press Ctrl+F2 key event in my application.

Can anyone suggest me that how to press the Ctrl+F2 event.

Thankyou.

lucian.teodorescu
Posts: 82
Joined: Fri Oct 24, 2014 10:58 am
Location: Bucharest

Re: How to press a key(Keyboard.Press) intstead of a click

Post by lucian.teodorescu » Mon Nov 16, 2015 3:52 pm

Hi ejji09,

Did you tried Add New Action > Key Shortcut? Choose that and replace 'X' with Ctrl+F2.

Hope it helps?
Lucian Teodorescu
NetSun Software

ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

Re: How to press a key(Keyboard.Press) intstead of a click

Post by ejji09 » Mon Nov 16, 2015 3:57 pm

Am using code module.

I want to press the key event Ctrl+F2 in code module, I think you you gave me the answer for recording module.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to press a key(Keyboard.Press) intstead of a click

Post by odklizec » Mon Nov 16, 2015 4:03 pm

You did not specify you look for code in your initial post ;)

Anyway, do you know you could examine code of each recorded action and even convert recorded actions to UserCode? Just select the recording action and press Ctrl+Enter. This shortcut should redirect you to code behind the selected recording action. Another way is to right click the selected action and from the appeared context menu select View Code.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

Re: How to press a key(Keyboard.Press) intstead of a click

Post by ejji09 » Mon Nov 16, 2015 4:24 pm

Am using code module to write my test case and for the keypress event i used the syntax as

code:

Code: Select all

Keyboard.Press("{ControlKey down}{F2}");
and it worked fine, but after the completion of the test case i was unable to type anything, all the keys in keyborad are not functioning and when i press the control key then all keysare working again and then i was able to type.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to press a key(Keyboard.Press) intstead of a click

Post by odklizec » Mon Nov 16, 2015 4:33 pm

Yes, it's because you probably never called {ControlKey up} in your code? In other words, if you want to use Keyboard.Press like you did, you must always use {ControlKey down} {ControlKey up} sequence. Otherwise, the Ctrl key remains stuck in down position.

Or use the code behind the suggested Key Shortcut, which looks like this:

Code: Select all

Keyboard.Press(System.Windows.Forms.Keys.F2 | System.Windows.Forms.Keys.Control, Keyboard.DefaultScanCode, Keyboard.DefaultKeyPressTime, 1, true);
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration