Modified WiiCade JavaScript API

Last Updated August 8, 2009

Download: Compressed with YUI Compressor Uncompressed

For those of you unfamiliar with the original: This is a library to assist your JavaScript code in getting information from Wii Remotes when your Web page is accessed from Wii's Internet Channel. You could just access opera.wiiremote manually, but this library gives you a few handy extras such as automatically setting up your script to accept input from the keyboard when your page is accessed from a PC, optionally preventing the default actions of the remote buttons, and numerous other nice things. It's a port of a similar library used in WiiCade's Flash games. Have a look at the official docs to see what it can do.

Pikadude No. 1's Modified version of the library includes these changes:

  1. All buttons (and on the PC, all keys) now have their default function enabled by default. This promotes a "take only what you need" approach, and also made it easier for me to implement change #2.
  2. On PCs, the library is much smarter about disabling the default actions of keys. Default actions are no longer disabled unless a key is mapped to a button with its default action disabled, so you can do fancy things like use <input type="text"> to allow text entry. Plus, disabling the default actions of special keys (such as the arrow keys) should work more reliably.
  3. Browser.setBackgroundColor was deleted. In my opinion, that sort of thing should be done by frameworks that specialize in such things, such as jQuery.

There are also some bug fixes, although I can't take credit for them. WiiCade, for who knows what reason, has made two versions of the library available. The easier-to-find version is available from WiiCade Labs, and it's also the older, buggier version. The Modified library is based on the newer version, which includes these changes:

  1. The script will run properly in Internet Explorer.
  2. Wii.getRemote(id).getCursorY() exists and works as advertised.
  3. Wii.getRemote(id).setRotated() works as advertised, instead of merely changing the value returned by Wii.getRemote(id).isRotated().

You can use this just like you'd use any JavaScript library - just plop a URL to where you've uploaded the file in a <script src> tag. The official download from WiiCade Labs may lead you to believe that the files game.html, Utilities.js, and main.js are necessary, but that will only be so if you're making a game that is to be submitted to WiiCade, in which case you can't use the Modified API anyways. Figure out what to do from your JavaScript code by reading the official docs, but if you're going to use KeyboardController, much of the information on keydown/keyup events from JavaScript Madness: Keyboard Events will also apply.

Both the Modified and official versions of the API suffer from some limitations not mentioned in the docs:

  1. twist, distance, and pointer events don't work at all.
  2. connected and disconnected events aren't triggered until you access the remote using one of the Wii.get functions.
  3. For remotes other than the primary remote, #2 also applies to buttondown and buttonup.
  4. There is no way to detect the B button on the primary remote.
  5. Browser.setDefaultEnabled(WiiRemote.BUTTON_1, false) doesn't work on a Wii, which will annoy the heck out of your players if you make the 1 button important and the Internet Channel's toolbar is set to Button Toggle.

Between the Modified WiiCade JavaScript API and jQuery, you should be able to easily craft some incredible JavaScript games (by the way, be aware that jQuery's fade effects don't work on the Wii). Good luck and have fun!

Download: Compressed with YUI Compressor Uncompressed

Back