-
Notifications
You must be signed in to change notification settings - Fork 1
/
Input.as
45 lines (36 loc) · 1.05 KB
/
Input.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package
{
import flash.display.*;
import flash.events.*;
public class Input
{
private static var keyboard : Object = new Object();
public static function attach (dispObj : DisplayObject) : void
{
dispObj.addEventListener( KeyboardEvent.KEY_DOWN, keyDownListener, false, 0, true );
dispObj.addEventListener( KeyboardEvent.KEY_UP, keyUpListener, false, 0, true );
dispObj.addEventListener( Event.ACTIVATE, activateListener, false, 0, true );
dispObj.addEventListener( Event.DEACTIVATE, deactivateListener, false, 0, true );
}
private static function keyDownListener( ev:KeyboardEvent ):void
{
keyboard[ev.keyCode] = true;
}
private static function keyUpListener( ev:KeyboardEvent ):void
{
keyboard[ev.keyCode] = false;
}
private static function activateListener( ev:Event ):void
{
keyboard = new Object();
}
private static function deactivateListener( ev:Event ):void
{
keyboard = new Object();
}
public static function keyPressed (key : uint) : Boolean
{
return keyboard[key];
}
}
}