Using the Wiimote buttons in Flash

WiiNintendo.net has posted a list of key codes that the various buttons on the Wiimote generate, stating that they work in Flash and JavaScript. Well, that's half accurate: They do work in JavaScript but not in Flash. Adding a Key listener in Flash doesn't register anything when the buttons on the Wiimote are pressed.

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?

Creative Commons LicenseThe 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.

34 Responses to “Using the Wiimote buttons in Flash”


  1. 1 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?

  2. 2 aral

    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.

  3. 3 John Giotta

    Perhaps you put a timer to steal focus back to the document to alleviate the Flash focus problem.

  4. 4 Richard 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.

  5. 5 aral

    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.

  6. 6 Richard 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.

  7. 7 alkmie

    http://wii.teamxlink.co.uk/

    how does this work?

  8. 8 Mario 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

  9. 9 Kevin

    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.

  10. 10 aral

    Hi Kevin,

    Sounds great — do let me know of your progress. In the meanwhile, have you seen Mario’s solution?

    http://aralbalkan.com/828

  11. 11 Matthieu

    Hello,
    thanks for this interesting search.
    Do you believe that is it possible to take a listener of wiimote’s moves in air?
    bye,
    Matt.

  12. 12 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

  13. 13 aral

    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

  14. 14 zharzone

    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.

  15. 15 frankie

    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.

  16. 16 Matt

    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.
    Wii = 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?

  17. 17 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.

  18. 18 Aral

    @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.

  19. 19 Chris

    Checkout wiiflash.org

  1. 1 BrokenBlog » Blog Archive » Wii Flash: The d-pad and buttons work!
  2. 2 The understated genius of my friend, Mario! at Aral Balkan
  3. 3 Monopolio Podcast .... el podcast más demandado
  4. 4 WiiOpera @ Wiki (PukiWiki/TrackBack 0.3)
  5. 5 Codebase » Blog Archive » Wii Flash
  6. 6 Nobien » Blog Archive » Flash + Wii?
  7. 7 flash platform! {desktop, mobile, touch screen…}
  8. 8 sweblog » Blog Archive » WiiFlash Beta
  9. 9 sweblog » Blog Archive » WiiFlash Release
  10. 10 blog aggregatore programmazione flash » Blog Archive » Other links for Wii and Flash
  11. 11 Creattica - Flash » Blog Archive » Playing Flash on the Wii
  12. 12 WiiOpera @ Wiki (PukiWiki/TrackBack 0.3)
  13. 13 Hackszine.com
  14. 14 鲸男与互动新媒体/Interactive » Blog Archive » ??wiimote?nunchck???
  15. 15 欢迎wiimote和nunchck两兄弟 于 鲸男与互动新媒体

Leave a Reply






Bad Behavior has blocked 0 access attempts in the last 7 days.