ARTICLE

Running a Windows Store Application From Windows Forms

Posted by Ibrahim Ersoy Articles | Windows Store Apps November 24, 2012
Before writing this article, I searched all over the Internet and was surprised that no one has ever thought of the power of "SendKeys".
Reader Level:
Download Files:
 

If you have used Windows 8 for at least a couple of months and have become accustomed to it, you should now know that the Metro UI is very easy to use.


You can click on a Windows Key (left or right doesn't matter), then click on a Metro app and it runs. The alternative way to run it is by clicking the Windows Key, writing the name of the application and pressing Enter. It runs!

So while I analyze its working process, I thought maybe I can send keys to the Metro UI. I can actually run Metro UI applications from a Windows Forms or Console App.

So here's how to do it.


1- First of all create a new Windows Forms Project:

metro1.png


2- Add a Button and by double-clicking on it create a click event handler for it.

3- Use this code:

 SendKeys.Send("^{ESC}");
SendKeys.Send("MetroTwit");
SendKeys.Send("{ENTER}");

An Explaination:

1st sendkeys code:    simulates the Windows Key, which actually is a CTRL + ESC keys combination.
2nd sendkeys code:  searches for the application that will run. For that I suggest you have a look at your apps first.
3rd sendkeys code:   sends an Enter key that will run the Windows Store Application.

Dont forget to change the 2nd sendkeys parameter according to your own Windows 8 Environment.

4- Run it!


When I clicked on the button it ran the App.

So here are some screenshots to my project:


Games:

metro2.png

metro3.png



Travel: 

metro2.png

metro4.png



MetroTwit:

metro2.png

metro5.png

As you can see, the code works perfectly!

So long story short, you can use 3 lines of code to fulfill your wish.

It would be so kind of you, if you shared your experience with it, so that I can update my article according to your experience using the code above.

Hope it helps!

Login to add your contents and source code to this article
post comment
     

Thank you Sam for the comment! About focus problem; Metro UI automatically got focus when you press Windows Key or click your mouse to leftmost-down corner.But i do understand what you say as i did years ago while i was developing for Visual Basic 6,the focus was always a problem.According to my machine test,full key sending operation lasts 1 sec.im sure there would be other machines it can last more than that,but in general Metro UI is a fast environment.And according to the nowadays PC hardware,i dont see any problem.All the keysending operations happen in a very fast way.But there would be problems,i might add: 1-While keysending if you press Windows Key,the keysending wont work. 2-if there is a classic windows application with same name,maybe it would not work,not tested though.The solution of these problems are unsolved.While the first one is User-Centric and the responsibility belongs to the user,the second one is OS-Centric which you cannot know to control it.Maybe you can check for installed packages and compare whether they have the same name or not but that would raise processing time which you refered in your comment.Lastly,i wrote this article to present the only way up to this time,not as an alternative.The problem is; you cannot run a Windows Store Application from outside by development.Because Metro UI is a special environment.i guess i wasnt clear enough in the article that this is not an alternative but the only way to do it :)

Posted by Ibrahim Ersoy Nov 24, 2012

I have seen many questions from beginners asking how to send keys and mouse input to other applications. It can be useful and it can be very frustrating. Beginners think it is an easy solution, but if the requirements are more complex then it can become so complicated to do using SendKeys that it is essentially impossible. One potential problem is focus; whatever control that keys are sent to must have the focus. Another problem is timing; you usually must wait for an application to process the keys. Another problem that often exists is that an application might need to "look" at the other application before knowing what to do, such as to check for errors. For requirements that are less simple than the appliation in this article, there are usually alternatives that beginners often avoid learning that would actually be esier and more reliable in the end. If you search for use of SendKeys in classic Windows applications, you will find many questions and articles including descriptions of the problems.

Posted by Sam Hobbs Nov 24, 2012
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.