Using the Wiimote buttons in Flash
My first thought was to use the Flash/JavaScript Integration Kit (since the player in the Wii is version 7, we can't use ExternalInterface) to relay the key events that the buttons generate from JavaScript to Flash. Easier said than done.
After some fiddling, I got the key codes to transfer to Flash but there are three show stoppers with this method:
First and foremost, it doesn't work when the Flash movie has focus. I tried every method I know of capturing events in JavaScript and none of them results in the JavaScript event handler being called when the Flash movie has focus and a key is pressed.)
Secondly, you cannot have a full screen Flash movie and use this method due to the way Flashjs works (it creates embeds a new SWF every time you call a method in Flash and passes the uid, method to call and its arguments as FlashVars to it. This SWF then uses the uid and LocalConnection to talk to your actual SWF.) So if your actual SWF takes up the whole screen, this additional SWF will result in a vertical scroll arrow displaying on the Wii.
Finally, even if the first two show stoppers could somehow be resolved, when the Flash/JS communication does work (i.e., when the page has focus), there is lag that would probably be unacceptable for games and even for interface items.
Also, the list of key codes given in the WiiNintendo.net article has two typos. The A button has a key code of 13, not 170 and the 2 button has a key code of 173, not 17. So the actual list of key codes for the Wiimote is:
↑ 175
↓ 176
→ 177
← 178
A 13
B 171
- 170
+ 174
1 172
2 173
The next thing I'm going to try is plain old SetVariable. But first a bout of tennis on the Wii with Dave!
If anyone has other ideas, I'm all ears. Please leave a note in the comments.
Update: So the tennis game can wait: SetVariable doesn't work on the Wii. Damn.
OK, so maybe I can use FSCommand to poll the JavaScript instead... *Doh!* Of course, I can't because functions called from FSCommand can't return values.
OK, so that's it from me. Ideas?
How about: Nintendo, please implement Key events for the Wiimote controller buttons like there are in JavaScript. Pretty please?
The Using the Wiimote buttons in Flash article by Aral Balkan, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial 2.0 UK: England License.
Subscribe to my blog






Jon B
I don’t get it, why don’t key presses register anything in flash - if nintendo think they do and opera probably has told them or agreed at least at some point and maybe adobe too then what is the issue with the flash player implementation that is causing them not to work? I can only think it has to be a bug, and in which case maybe it will be resolved when the final opera browser ships?
Does both the event listener method and the old skool way of attaching key events fail?
This has to be something that will get fixed - otherwise what is the point?
December 28th, 2006 at 11:57 pmaral
Hi Jon,
I’m not sure whether it’s a bug or a feature
It may just be that Nintendo doesn’t want Flash developers competing too readily with their own games, etc. Of course, it could also just be a bug. I have no inside information either way on the subject.
Using the Key listener doesn’t work and neither does polling Key.isDown on enterFrame. I didn’t try an onClipEvent, but that really shouldn’t make a difference.
Even without the other buttons, there are a world of applications that can be built in Flash for the Wii. Having the other buttons, of course, would make it even better — especially for Flash games.
December 29th, 2006 at 1:04 pmJohn Giotta
Perhaps you put a timer to steal focus back to the document to alleviate the Flash focus problem.
December 29th, 2006 at 4:25 pmRichard Leggett
Does LocalConnection work? If so how about just writing a new SWF on each keypress? I’m working on a gesture recogniser right now so will post if I have some luck today. p.s. My code is 2764 0630 2609 7929.
December 29th, 2006 at 5:28 pmaral
Hey Richard,
That’s how the Flash/JS Integration Kit works but, at least in my tests, the browser window needed to have focus for it to work and there was a lag.
December 29th, 2006 at 6:00 pmRichard Leggett
Ah sorry
Ok well “phase one” is complete, it will recognise a backslash, forward slash and circle gesture (across the entire screen/grid only, as I haven’t implemented up/downscaling of gestures due to CPU cost at present).
http://richardleggett.co.uk/wii
Tomorrow I have some things to do like find a new place to live but will have a simple game up using this shortly. It’s not as good as I hoped, but with some refining (and practice for the user) I think it could be used for simple 2-5 gesture games (particularly if I can get upscaling working).
Also you will notice at the moment I have opted for a low-res grid, with the classes I have no you can alter this but onMouseMove on the Wii is not as responsive or frequent as with the desktop, so keeping the resolution nice and low means you get more “hits”, again I’m going to tweak later on.
December 30th, 2006 at 1:47 amalkmie
http://wii.teamxlink.co.uk/
how does this work?
December 31st, 2006 at 2:41 pmMario Klingemann
I’ve come up with a method that seems to work quite well (at least I’d say that there is no lag), except for an optical glitch that is caused by Opera treating the navigation cross also as a TAB key in order to switch the keyboard focus: http://www.quasimondo.com/archives/000638.php
January 1st, 2007 at 5:46 pmKevin
I have a library that does something similar to FlashJS, but might have a little less lag (to my knowledge, FlashJS appends a query string to the swf url every time it sends a message to Flash, which causes the browser to redownload the swf file from the server every time - my version does not).
You can check this out here (the example is broken atm): http://www.unfocus.com/projects/source/
I haven’t updated the communication stuff much recently, since ExternalInterface is becoming the standard, but it should still work. When I get a Wii (probably in the next few weeks) I will certainly see if I can come up with something to help out (although, I’m sure someone will figure out how to do this before I get to it).
Kevin N.
January 2nd, 2007 at 7:57 pmaral
Hi Kevin,
Sounds great — do let me know of your progress. In the meanwhile, have you seen Mario’s solution?
http://aralbalkan.com/828
January 3rd, 2007 at 5:04 pmMatthieu
Hello,
January 5th, 2007 at 9:57 amthanks for this interesting search.
Do you believe that is it possible to take a listener of wiimote’s moves in air?
bye,
Matt.
Adam
Aral,
I’ve been playing with a different solution for the desktop, allowing me to get full two way Wiimote/Flash communication including info from the motion sensors, all buttons, nunchuck etc, and allowing Flash to control the Wiimote’s rumble and lights. It’s not really an end user solution as it relies on a bunch of other apps for communication, but with a bit more refinement could prove handy for demos and installations…
http://www.dustypixels.com/blog/2007/01/29/wiimote-flash-first-two-way-communication-tests/
A
January 29th, 2007 at 11:33 amaral
Hey Adam,
That is very cool. I couldn’t find any contact info on your blog — can you email me if you get this (aral at the domain of this site.) Would love to talk to you.
Aral
January 29th, 2007 at 12:14 pmzharzone
Hi Aral,
Have you managed to get some info regarding Adam’s demo? From what I can conclude he wrote some application that captures Wii’s movements/clicks and translates them into keyboard presses/mouse movements that flash responces to. My only question is how did he managed to return the data back to Wii (leds switching/ vibration function)? Also, how in the hell is the controller hooked up on the PC?
Quite impressive.
February 7th, 2007 at 9:32 pmfrankie
The wiimote is connected using a bluetooth usb adapter. They cost about 10 to 60 bucks. Try bestbuy. The 35 dollar one works for sure. I have it.
February 18th, 2007 at 10:31 pmMatt
I’ve always been trying to make games for comercial game systems, and have found that you can sometimes just find the PC keyboard keys that corospond to the game systems controls. After playing a few games designed for the wii that use the wiimotes buttons, I think I’ve found a few keys.
April 28th, 2007 at 2:39 pmWii = PC
D-Pad = arrow keys
1 = a
2 = s
Let me know if I’m wrong, but I think they work. So, wouldn’t it just be as simple as programing the flash to respond to those PC keys instead?
dvanex
If you want the short answer, no. The problem is that the version of flash on the wii cannot or cannot with typical functions interpret butons from the wiimote. Mabye it would be possible to, as adam has done recieve the wiimotes bluetooth data on a computer. The data could be modified by a program to contain key signatures that flash could interperate. It could then transmit the modified data to the wii and viola, you now have a solution that will have cost you hundreds of hours and dollars, if it works.
July 13th, 2007 at 5:51 amAral
@dvanex: Check out Mario’s solution in the trackbacks. He uses a generated SWF and LocalConnection to proxy the key codes from JavaScript to Flash. Works really well. So yes, it can be done
It would be better if native support was added in the future though.
July 13th, 2007 at 9:36 amChris
Checkout wiiflash.org
September 7th, 2007 at 11:35 pmgautam
I have one php page in that i include few javascript code for auto load purpose of this page but this thing is run on this page when no event fire on screen for few minute then and then only auto page reload otherwise not like a screen saver if our mouse move or click or scroll or any key press user with keyboard then screen saver is not working
This thing you give nice but is it possible this thing in java script.
December 25th, 2008 at 1:34 pm