Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions org/flixel/system/input/Input.as
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ package org.flixel.system.input
*/
public class Input
{
// Values of "key.current" (for reference)
// 0 - Not pressed
// 2 - Just pressed
// 1 - Pressing
// -1 - Just released

/**
* @private
*/
Expand Down Expand Up @@ -146,6 +152,19 @@ package org.flixel.system.input
return _lookup[KeyName];
}

/**
* Look up the key's name for a given key code. Useful for "change controls" menus.
*
* @param KeyCode The KeyCode for the key.
*
* @return The name of that key.
*/
public function getKeyName(KeyCode:uint):String
{
var key:Object = _map[KeyCode];
return (key) ? key.name : "[key #" + KeyCode + "]";
}

/**
* Check to see if any keys are pressed right now.
*
Expand All @@ -163,6 +182,40 @@ package org.flixel.system.input
return false;
}

/**
* Check to see if any keys were just pressed.
*
* @return Whether any keys were just pressed.
*/
public function justPressedAny():Boolean
{
var i:uint = 0;
while(i < _total)
{
var o:Object = _map[i++];
if((o != null) && (o.current == 2))
return true;
}
return false;
}

/**
* Check to see if any keys were just released.
*
* @return Whether any keys were just released.
*/
public function justReleasedAny():Boolean
{
var i:uint = 0;
while(i < _total)
{
var o:Object = _map[i++];
if((o != null) && (o.current == -1))
return true;
}
return false;
}

/**
* An internal helper function used to build the key array.
*
Expand Down