Using C# to wait for keyboard input

Ask general questions here.
macgowan
Posts: 14
Joined: Mon Jun 23, 2014 9:20 pm

Using C# to wait for keyboard input

Post by macgowan » Thu Jan 08, 2015 11:26 pm

Hi ...

I would like to wait for some keyboard input using C# in a Ranorex text module.

I have been looking at some of the various classes:
Keyboard Class (.NET Framework 4.5)

Any suggestions.

[language=]
Report.Info("Wait for key press");

// Uses the Keyboard.IsToggled to determine if a key is toggled.
if (Keyboard.IsKeyToggled(Key.Return))
{
// btnIsToggle.Background = Brushes.Red;
Report.Info("1");
}
else
{
// btnIsToggle.Background = Brushes.AliceBlue;
Report.Info("2");
}
[/language]

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Using C# to wait for keyboard input

Post by Support Team » Fri Jan 09, 2015 2:37 pm

Hi macgowan,

May I ask you why you need to wait for any keyboard input? There may be another better solution to fulfill your requirements.

Regards,
Markus
.
Image

macgowan
Posts: 14
Joined: Mon Jun 23, 2014 9:20 pm

Re: Using C# to wait for keyboard input

Post by macgowan » Fri Jan 09, 2015 9:14 pm

Hi Markus,

It's for pausing the automation - allowing me to manually take control of the application.

Today (running normally) - We start the ranorex automated test suite - we create some test data on the fly - then start the automated test cases - when the test are complete the test data is cleaned up.

Today (taking control during a run) - We start the ranorex automated test suite - we create some test data on the fly - then start the automated test cases - I use the Pause/Break key to stop the automation so I can manually control the application. The test data is NOT cleaned up as the suite has terminiated.

Detecting a key press --

We start the ranorex automated test suite - we create some test data on the fly - then start the automated test cases - The test case waits for a specific keypress (F11). During this time I can manually control the application. When F11 is pressed the test case will continue and the test data will be cleaned up.

If there is a better way - that's great.

Thanks,
Chris

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

Re: Using C# to wait for keyboard input

Post by krstcs » Fri Jan 09, 2015 9:47 pm

Why don't you have Ranorex do all of it? That is what it is designed to do. You can create and manipulate data with Ranorex.

Is there some part of the process that cannot be automated for some reason? Can you explain it to us? Maybe we can think of something you haven't thought of, or maybe the Ranorex team knows something else you can do.

Just seems to me that you bought an airplane and, instead of flying it where you need it, you are towing it on the road... :D
Shortcuts usually aren't...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Using C# to wait for keyboard input

Post by Support Team » Mon Jan 12, 2015 12:50 pm

Hi macgowan,

A workaround could be adding a Console.WriteLine(); in your code in order to wait for a Keyboard input.
This should do the trick.

Regards,
Bernhard
.
Image

macgowan
Posts: 14
Joined: Mon Jun 23, 2014 9:20 pm

Re: Using C# to wait for keyboard input

Post by macgowan » Tue Jan 13, 2015 10:28 pm

Thanks Bernard -

@krstcs » Thanks for your comments and suggestions -- I'm just using the 'manual process' to do some debugging and getting the application loaded --- It is easier than Logging into the application, Adding some GUID and doing some other stuff that is all done automatically when I use Ranorex :--)

Don't worry we are using the 'airplane' - the automated tests (130 ranorex test cases) are running in a continuous integration environment - with regression running in TEST, UAT and QA every night :--)

Thanks,
Chris

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

Re: Using C# to wait for keyboard input

Post by krstcs » Wed Jan 14, 2015 2:48 pm

Got it! :D

I do have times when I do some manual interaction, such as message boxes at certain spots for user input to confirm extra-software processes like printing, so I understand, just wanted to make sure you weren't trying to over-think it (which I also tend to do...).
Shortcuts usually aren't...