So I’ve been working on a cool tool called Wirepad its a wireless gamepad for windows phone 7 and in the interest of sharing my development process i would like to present this guide of how i came about the idea and how i developed it.
So the concept came about as i was sitting at home playing a very popular game involving an Italian plumber and a clingy princess i was using my keyboard and the experience was not great so i did some surfing to find some kind of xbox 360 controller receiver dongle? and a ps3 controller driver hack but none of these options really seemed 1? cost effective or 2? easy and reliable… so i decided there must be an app for this and sadly.. there wasn’t.
Using my some crazy googlefoo i sourced myself a vector image of a controller to represent the input on the screen of my phone with a little bit of image editing i found a size where the buttons felt comfortable enough to use and play a game with.
I opend up my copy of visual studio express and created a new Windows Phone 7 Project i experimented with silverlight buttons on an xaml form in the shape of the controller image. i set their text to blank and border styles to invisible and monitored the button presses of each button this seemed to work okay for testing.
Then i began to create a tcp server windows forms application it basically sits and listens on port 8888 for a connection this was the start of my debug test bed.
With a server listening and the basics of a windows phone 7 app working i felt it necessary to begin working on the tcp client stage of things my initial setup would connect to the server on port 8888 and then send the Buttons ID and the current state i.e. “Button1|Pressed” “Button1|Depressed” this was working i was seeing these states appearing on my tcp server application.
Once all the buttons had been mapped and created i began writing a button state manager on the server side to handle mapping between TCP Packets and key presses initially this used the .net api’s “Send Keys” method i found that this did not work in all emulators as sendkeys does not simulate a hardware keypress at the lower levels.
I did some more googlefoo and found about a windows api called SendInput which sends low level keystrokes and has the ability to send Pressed and Released at different times this was perfect for my needs. so i wrote a wrapper that can call this function and fit my needs for a virtual keypad and replaced the sendkeys function with my wrappers ‘SendKeyPress’ or ‘SendKeyUp’ functions this worked really well.
It was then that i realized my next problem because i had used buttons in the app i was unable to press multiple buttons at once due to wp7 silverlight limitations so i switched to XNA and wrote my own button handling script the only issue was i had to send the state of each button every frame, it was slow! i timed it to about 40 milliseconds slow and it made our Italian plumber unbearably hard to move.
Optimizing the packets somewhat helped reducing our latency down to about 30 milliseconds but sending the state of each button every frame of video seemed like a waste so i put a timer in there to send the key presses every 15 milliseconds and store them in some kind of buffer this made it faster but something was still wrong.
With some more development i switched the system back to button ON OFF States and managed to get it to send 1 packet when the state changes rather than every frame this brought the speed down to about 10 milliseconds PLAYABLE!
Some gui design later for server selection etc and wirepad was finished.
Thank you for reading this i hope it was insightful to my development process
If your interested to see the final product it is available here.