Well, I couldn not restrain myself..and while I should have been working, I did this: multiple keys support, configurable as you wish.
First of all, add these 2 new classes:
package com.adamatomic.flixel
{
public class FlxKeyControl
{
private var KEYS:Array = new Array();//array of keys
public var unknownKeyCallback:Function = null;
public function AddKey(keyCode:int, keyName:String):void
{
KEYS.push( new FlxKey(keyCode, keyName));
}
public function ResetKeys():void
{
for (var i:uint = 0; i < KEYS.length; i++)
{
var k:FlxKey;
k = KEYS[i] as FlxKey;
k.kPressed = 0;
}
}
public function Pressed(name:String):Boolean
{
//look for key
for (var i:uint = 0; i < KEYS.length; i++)
{
var k:FlxKey;
k = KEYS[i] as FlxKey;
if ( k.kName == name)
return k.kPressed > 0;
}
return false;//key does not exists
}
public function JustPressed(name:String):Boolean
{
//look for key
for (var i:uint = 0; i < KEYS.length; i++)
{
var k:FlxKey;
k = KEYS[i] as FlxKey;
if ( k.kName == name)
return k.kPressed == 2;
}
return false;//key does not exists
}
public function JustReleased(name:String):Boolean
{
//look for key
for (var i:uint = 0; i < KEYS.length; i++)
{
var k:FlxKey;
k = KEYS[i] as FlxKey;
if ( k.kName == name)
return k.kPressed == -1;
}
return false;//key does not exists
}
//-------
//mimic flixel key logic !
public function PressKey(code:int):void
{
var notFound:Boolean = true;//I will use this in the next release !!!
//look for key
for (var i:uint = 0; i < KEYS.length; i++)
{
var k:FlxKey;
k = KEYS[i] as FlxKey;
if ( k.kCode == code)
{
notFound = false;
//found !
if(k.kPressed > 0)
k.kPressed = 1;
else
k.kPressed = 2;
}
}
if (unknownKeyCallback != null && notFound)
{
//unknown key and callbackfuncion ( maybe for a config screen )
unknownKeyCallback(code);
}
}
public function ReleaseKey(code:int):void
{
//look for key
for (var i:uint = 0; i < KEYS.length; i++)
{
var k:FlxKey;
k = KEYS[i] as FlxKey;
if ( k.kCode == code)
{
//found !
if(k.kPressed > 0)
k.kPressed = -1;
else
k.kPressed = 0;
}
}
}
public function UpdateKeys():void
{
for (var i:uint = 0; i < KEYS.length; i++)
{
var k:FlxKey;
k = KEYS[i] as FlxKey;
if ( (k.kOldValue == -1) && (k.kPressed == -1))
k.kPressed = 0;
else if ( (k.kOldValue == 2) && (k.kPressed == 2))
k.kPressed = 1;
k.kOldValue = k.kPressed;
}
}
//-----------
}
}
package com.adamatomic.flixel
{
public class FlxKey
{
public var kCode:int;//key code
public var kPressed:int;//was pressed ?
public var kOldValue:int;//Flixel stuff...
public var kName:String;//name your key, ex: "PLAYER1_UP"
//CONSTRUCTOR
public function FlxKey(code:int, name:String)
{
kCode = code;
kName = name;
}
}
}
Make sure to add them in the flixel folder and name the files FlxKeyControl.as and FlxKey.as.
Then, open FlxG.as and:
1)Add the following attribute
static private var KEYCONTROL:FlxKeyControl = new FlxKeyControl();
and method:
static public function AddKey(keyCode:int, keyName:String):void { KEYCONTROL.AddKey(keyCode, keyName);}
2)Replace the following methods:
static public function resetKeys():void { KEYCONTROL.ResetKeys(); }
static public function setUnknownCallback(callBackFunction:Function):void { KEYCONTROL.unknownKeyCallback = callBackFunction; }
static public function unsetUnknownCallback():void { KEYCONTROL.unknownKeyCallback = null; }
static public function pressed(KeyName:String):Boolean { return KEYCONTROL.Pressed(KeyName); }
static public function justPressed(KeyName:String):Boolean { return KEYCONTROL.JustPressed(KeyName); }
static public function justReleased(KeyName:String):Boolean { return KEYCONTROL.JustReleased(KeyName); }
and
//@desc This function is only used by the FlxGame class to do important internal management stuff
static internal function pressKey(k:int):void
{
KEYCONTROL.PressKey(k);
}
//@desc This function is only used by the FlxGame class to do important internal management stuff
static internal function releaseKey(k:int):void
{
KEYCONTROL.ReleaseKey(k);
}
//@desc This function is only used by the FlxGame class to do important internal management stuff
static internal function updateKeys():void
{
KEYCONTROL.UpdateKeys();
//mouse handle untouched !
mouse.x = state.mouseX-scroll.x;
mouse.y = state.mouseY-scroll.y;
}
_keys and _oldKeys are not longer necessary, comment them or errase them
Now, open FlxGame.as and replace:
//@desc This function is only used by the FlxGame class to do important internal management stuff
private function onKeyUp(event:KeyboardEvent):void
{
var code:String = String.fromCharCode(event.charCode);
FlxG.releaseKey(event.keyCode);
//WATCH OUT SETTING THIS KEYS !!!
if ((code == '0') || (code == ')')) {
FlxG.setMute(!FlxG.getMute());
showSoundTray();
} else if ((code == '-') || (code == '_')) {
FlxG.setMute(false);
FlxG.setMasterVolume(FlxG.getMasterVolume() - 0.1);
showSoundTray();
} else if ((code == '+') || (code == '=')) {
FlxG.setMute(false);
FlxG.setMasterVolume(FlxG.getMasterVolume() + 0.1);
showSoundTray();
} else if ((code == '1') || (code == '!') || (code == '~') || (code == '`')) {
toggleConsole();
}
}
//@desc This function is only used by the FlxGame class to do important internal management stuff
private function onKeyDown(event:KeyboardEvent):void
{
var code:String = String.fromCharCode(event.charCode);
FlxG.pressKey(event.keyCode);
}
And finally comment FlxG.releaseKey(6); and FlxG.pressKey(6); inside onMouseUp and onMouseDown
To use this is pretty simple:
In the state constructor add a line:
FlxG.AddKey(KeyCode, KeyName);
where KeyCode is the key code number (d'uh

) and KeyName is any name you want for that key.
To check, use
pressed(KeyName), justPressed(KeyName) or justReleased(KeyName) as you wuold normally do...but now you use the name you setted for the key instead of a Flixel constant ( remember to save those names somewhere ).
Only problem: you loose kUp, kDown, kA, etc. etc. etc...but you can add as many keys as you want ( uhm, I think I'll have to add some security to avoid binding to Flixel function keys as +,-, etc. ).
Mouse support is "almost" untouched: you can no longer use pressed,justPressed or justReleased...but you still can use kMouse
You can test it here:
http://www.swfcabin.com/open/1245247090Try any letter on my nickname

Hope I didn't miss anything. Yell me if I did

Oh, I almost forgot: what setUnknownCallback used for ? Set a callback function using this method, then, when an unknown keyis press, this function will be called, recieving the unknown's key code. Use it for a config screen. I still haven't tested it, but I think it should work.
I don't have to tell you what unsetUnknownCallback does....
