0 comments

ok, so you don't need any WPF at all to actually control you computer using a wiimote, but everyone loves the simplicity of making and controlling a gui with WPF that we should use it anyway's! Plus, WPF is just cool. Anyway, using Brian Peek's Managed Library for the Wiimote (I used version 1.2.0.0) you can receive data from the wiimote about its IR coordinates (up to all 4 IR sensors now!) and all of its button states. Since we can receive the wiimotes IR coordinates, we can tell our application to point the mouse cursor to those coordinates. It's that easy!

WiimoteMouseControlWPF_App 

But of course things are not always that easy all the time. With WPF and its new System.Windows.Input namespace, Microsoft introduces a new way to control input devices such as the mouse. I did some basic research (and maybe not enough) and found out that there is no easy way to tell the mouse cursor where to point to in WPF. With winforms you could say:

Cursor.Position = new Point(50, 50);

and that would set the cursor to a point at 50 pixels from the left and 50 pixels from the top, with 0,0 being at the upper-left of the screen. So after finding no easy way to do this in WPF I decided to use this winforms method instead. I used the midpoint of 2 IR sensors (version 1.2.0.0 only received data from 2 IR sensors) and set the position of the cursor to that point. This allows me to move my wiimote and the cursor moves as well!

I then added some simple functionality to mimic a mouse using the wiimote. This was much more difficult than I had anticipated; I had to use some Win32 api calls. I mainly used SendInput() that allowed me to send mouse events to the computer. The different mouse events that I used were:

  • Left button down
  • Left button up
  • Right button down
  • Right button up

These events allowed me to simulate a click event for the left click and for the right click. However, there is a small bug. When clicking (left or right click) on a menu and then moving the mouse over a submenu item seems to actually select the that item. If I get that interested in this bug I will try to fix it, however there are other projects that I would like to start up. Also of note, I found these Win32 api calls from a forum. The wiimote buttons that map to the mouse are as follows:

  • Home -> closes the application
  • A button (down) -> Left button down
  • A button (up) -> Left button up
  • A button twice consecutive -> Left button double click
  • B -> Left button click
  • Plus -> Right button click

Upon receiving updated data from the wiimote I use simple setters to set my boolean properties that in turn cause the cursor to update its position or send a Win32 call for a mouse event. There could have been better approaches (data binding?) than this implementation, but this was the simplest way for me to code; yes I was a bit lazy this time ;)

WiimoteMouseControlWPF_TrayIcon

One other thing I have added to this application is that when you minimize it, it goes into the taskbar as an icon. This way you can run the application and minimize it out of the way while you control you computer! Enjoy this application and let me know what other buttons / controls you would like me to add. If I get some responses I will look into adding those features.

filefile size
WiimoteMouseControl Source.zip21.61 KB
WiimoteMouseControl App.zip17.35 KB

2 comments

I'm sure almost everyone knows about the Nintendo wii. It uses a different type of controller that is a real ingenious piece of equipment. The controller is the wiimote that has some awesome sensors in it. Much more detailed information can be found at the WiiLi Wiki. There are links that describe what type of sensors the wiimote has and how it works. There are also links that describe the data the the wiimote passes to the wii.

Now that's one cool input device if you ask me, but what does this wiimote do for us? Well, since it is a bluetooth device you can connect this guy to you computer pretty easily; all you need is a bluetooth adapter or built in bluetooth on your computer. Once connected you can use some programming language to interrupt the data that the wiimote sends to the computer. Brian Peek has written a nifty managed library for the wiimote that I have used (at the time of writing this I am using version 1.2.0.0). He also lists other projects that are using his library; some really cool ones at that. And of course, the guy who has started this phenomenon is Johnny Chung! Thanks to everyone for putting together their projects so I could learn and finally create one of my own ... and yes, there will be more to come.

WiimoteWPF_ScreenShot_Thumb

So for this first part in my wiimote application, I have built a wiimote status app using wpf. My application lets the user connect to the wiimote and it displays a lot of data that the wiimote is telling the computer; mainly its IR coordinates, accelerometer data, button states and extension status. You can also use my application to toggle the LED's and the rumble feature on the wiimote. To get valid IR coordinates (and some round circles to move on the application) you need to point the wiimote at some IR light source. Incandescent light bulbs will work as well, or even the actual wiimote sensor bar! Speaking of the sensor bar, I built my own version using some IR LED's similar to this one. However, there were some difficulties in putting the final product into the casing I had and in the end I broke an LED, so my homemade sensor bar is sitting in a bad currently.

Hopefully you will enjoy this project and all that it has to offer. It really was a good introductory to learning how to use the managed library and to better understand the wiimote. I know there has been talk about tracking multiple points using the wiimote and Matthias Shapiro is currently looking into this using wpf as well. Check out his wii data visualizer, he has some great ideas on how to show some of the wii data!

There seems to be plenty of people out there that are starting to use the wiimote as a great input device. If you have any questions or thoughts about what projects I should try to accomplish, let me know. And let me know what you think about my application as well!

filefile size
WiimoteWPF Source.zip110.1 KB