Page 1 of 1

Using C# to wait for keyboard input

Posted: Thu Jan 08, 2015 11:26 pm
by macgowan
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]

Re: Using C# to wait for keyboard input

Posted: Fri Jan 09, 2015 2:37 pm
by Support Team
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

Re: Using C# to wait for keyboard input

Posted: Fri Jan 09, 2015 9:14 pm
by macgowan
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

Re: Using C# to wait for keyboard input

Posted: Fri Jan 09, 2015 9:47 pm
by krstcs
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

Re: Using C# to wait for keyboard input

Posted: Mon Jan 12, 2015 12:50 pm
by Support Team
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

Re: Using C# to wait for keyboard input

Posted: Tue Jan 13, 2015 10:28 pm
by macgowan
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

Re: Using C# to wait for keyboard input

Posted: Wed Jan 14, 2015 2:48 pm
by krstcs
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...).