package classes.Box2D.General 
{
    import flash.display.*;
    import flash.events.*;
    
    public class Input extends Object
    {
        public function Input(arg1:flash.display.Sprite)
        {
            var loc1:*=0;
            var loc2:*=0;
            super();
            m_stageMc = arg1;
            ascii = new Array(222);
            fillAscii();
            keyState = new Array(222);
            keyArr = new Array();
            loc1 = 0;
            while (loc1 < 222) 
            {
                keyState[loc1] = new int(0);
                if (ascii[loc1] != undefined)
                {
                    keyArr.push(loc1);
                }
                ++loc1;
            }
            bufferSize = 5;
            keyBuffer = new Array(bufferSize);
            loc2 = 0;
            while (loc2 < bufferSize) 
            {
                keyBuffer[loc2] = new Array(0, 0);
                ++loc2;
            }
            arg1.stage.addEventListener(flash.events.KeyboardEvent.KEY_DOWN, keyPress, false, 0, true);
            arg1.stage.addEventListener(flash.events.KeyboardEvent.KEY_UP, keyRelease, false, 0, true);
            arg1.stage.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, mousePress, false, 0, true);
            arg1.stage.addEventListener(flash.events.MouseEvent.CLICK, mouseRelease, false, 0, true);
            arg1.stage.addEventListener(flash.events.MouseEvent.MOUSE_MOVE, mouseMove, false, 0, true);
            arg1.stage.addEventListener(flash.events.Event.MOUSE_LEAVE, mouseLeave, false, 0, true);
            mouse.graphics.lineStyle(0.1, 0, 100);
            mouse.graphics.moveTo(0, 0);
            mouse.graphics.lineTo(0, 0.1);
            return;
        }

        public function mouseRelease(arg1:flash.events.MouseEvent):*
        {
            mouseDown = false;
            mouseReleased = true;
            return;
        }

        public function keyPress(arg1:flash.events.KeyboardEvent):*
        {
            keyState[arg1.keyCode] = Math.max(keyState[arg1.keyCode], 1);
            lastKey = arg1.keyCode;
            return;
        }

        private function fillAscii():*
        {
            ascii[65] = "A";
            ascii[66] = "B";
            ascii[67] = "C";
            ascii[68] = "D";
            ascii[69] = "E";
            ascii[70] = "F";
            ascii[71] = "G";
            ascii[72] = "H";
            ascii[73] = "I";
            ascii[74] = "J";
            ascii[75] = "K";
            ascii[76] = "L";
            ascii[77] = "M";
            ascii[78] = "N";
            ascii[79] = "O";
            ascii[80] = "P";
            ascii[81] = "Q";
            ascii[82] = "R";
            ascii[83] = "S";
            ascii[84] = "T";
            ascii[85] = "U";
            ascii[86] = "V";
            ascii[87] = "W";
            ascii[88] = "X";
            ascii[89] = "Y";
            ascii[90] = "Z";
            ascii[48] = "0";
            ascii[49] = "1";
            ascii[50] = "2";
            ascii[51] = "3";
            ascii[52] = "4";
            ascii[53] = "5";
            ascii[54] = "6";
            ascii[55] = "7";
            ascii[56] = "8";
            ascii[57] = "9";
            ascii[32] = "Spacebar";
            ascii[17] = "Ctrl";
            ascii[16] = "Shift";
            ascii[192] = "~";
            ascii[38] = "up";
            ascii[40] = "down";
            ascii[37] = "left";
            ascii[39] = "right";
            ascii[96] = "Numpad 0";
            ascii[97] = "Numpad 1";
            ascii[98] = "Numpad 2";
            ascii[99] = "Numpad 3";
            ascii[100] = "Numpad 4";
            ascii[101] = "Numpad 5";
            ascii[102] = "Numpad 6";
            ascii[103] = "Numpad 7";
            ascii[104] = "Numpad 8";
            ascii[105] = "Numpad 9";
            ascii[111] = "Numpad /";
            ascii[106] = "Numpad *";
            ascii[109] = "Numpad -";
            ascii[107] = "Numpad +";
            ascii[110] = "Numpad .";
            ascii[45] = "Insert";
            ascii[46] = "Delete";
            ascii[33] = "Page Up";
            ascii[34] = "Page Down";
            ascii[35] = "End";
            ascii[36] = "Home";
            ascii[112] = "F1";
            ascii[113] = "F2";
            ascii[114] = "F3";
            ascii[115] = "F4";
            ascii[116] = "F5";
            ascii[117] = "F6";
            ascii[118] = "F7";
            ascii[119] = "F8";
            ascii[188] = ",";
            ascii[190] = ".";
            ascii[186] = ";";
            ascii[222] = "\'";
            ascii[219] = "[";
            ascii[221] = "]";
            ascii[189] = "-";
            ascii[187] = "+";
            ascii[220] = "\\";
            ascii[191] = "/";
            ascii[9] = "TAB";
            ascii[8] = "Backspace";
            return;
        }

        public function mouseMove(arg1:flash.events.MouseEvent):*
        {
            if (mouseDown != arg1.buttonDown)
            {
                mouseDown = arg1.buttonDown;
                mouseReleased = !arg1.buttonDown;
                mousePressed = arg1.buttonDown;
                mouseDragX = 0;
                mouseDragY = 0;
            }
            mouseX = arg1.stageX - m_stageMc.x;
            mouseY = arg1.stageY - m_stageMc.y;
            mouseOffsetX = mouseX - mouse.x;
            mouseOffsetY = mouseY - mouse.y;
            if (mouseDown)
            {
                mouseDragX = mouseDragX + mouseOffsetX;
                mouseDragY = mouseDragY + mouseOffsetY;
            }
            mouse.x = mouseX;
            mouse.y = mouseY;
            return;
        }

        public function keyRelease(arg1:flash.events.KeyboardEvent):*
        {
            var loc1:*=0;
            keyState[arg1.keyCode] = -1;
            loc1 = (bufferSize - 1);
            while (loc1 > 0) 
            {
                keyBuffer[loc1] = keyBuffer[(loc1 - 1)];
                loc1 = (loc1 - 1);
            }
            keyBuffer[0] = [arg1.keyCode, 0];
            return;
        }

        public function mouseLeave(arg1:flash.events.Event):*
        {
            mouseReleased = mouseDown;
            mouseDown = false;
            return;
        }

        public function mousePress(arg1:flash.events.MouseEvent):*
        {
            mousePressed = true;
            mouseDown = true;
            mouseDragX = 0;
            mouseDragY = 0;
            return;
        }

        public static function getKeyHold(arg1:int):int
        {
            return Math.max(0, keyState[arg1]);
        }

        public static function update():*
        {
            var loc1:*=0;
            var loc2:*=0;
            loc1 = 0;
            while (loc1 < keyArr.length) 
            {
                if (keyState[keyArr[loc1]] != 0)
                {
                    var loc3:*;
                    var loc4:*;
                    var loc5:*=((loc3 = keyState)[(loc4 = keyArr[loc1])] + 1);
                    loc3[loc4] = loc5;
                }
                ++loc1;
            }
            loc2 = 0;
            while (loc2 < bufferSize) 
            {
                loc5 = ((loc3 = keyBuffer[loc2])[(loc4 = 1)] + 1);
                loc3[loc4] = loc5;
                ++loc2;
            }
            mouseReleased = false;
            mousePressed = false;
            mouseOver = false;
            return;
        }

        public static function isKeyPressed(arg1:int):Boolean
        {
            timeSinceLastKey = 0;
            return keyState[arg1] == 1;
        }

        public static function isKeyDown(arg1:int):Boolean
        {
            return keyState[arg1] > 0;
        }

        public static function getKeyString(arg1:uint):String
        {
            return ascii[arg1];
        }

        public static function isKeyReleased(arg1:int):Boolean
        {
            return keyState[arg1] == -1;
        }

        public static function isKeyInBuffer(arg1:int, arg2:int, arg3:int):*
        {
            return keyBuffer[arg2][0] == arg1 && keyBuffer[arg2][1] <= arg3;
        }

        
        {
            lastKey = 0;
            timeSinceLastKey = 0;
            mouseDown = false;
            mouseReleased = false;
            mousePressed = false;
            mouseOver = false;
            mouseX = 0;
            mouseY = 0;
            mouseOffsetX = 0;
            mouseOffsetY = 0;
            mouseDragX = 0;
            mouseDragY = 0;
            mouse = new flash.display.Sprite();
        }

        public static var mouseOffsetX:Number=0;

        private static var keyArr:Array;

        public static var mouseDragX:Number=0;

        public static var mouseDragY:Number=0;

        public static var mouseOffsetY:Number=0;

        public static var ascii:Array;

        public static var mouseX:Number=0;

        public static var mouseY:Number=0;

        public static var mouseOver:Boolean=false;

        private static var bufferSize:int;

        public static var mouse:flash.display.Sprite;

        public static var mouseDown:Boolean=false;

        public static var mouseReleased:Boolean=false;

        public static var lastKey:int=0;

        public static var m_stageMc:flash.display.Sprite;

        private static var keyState:Array;

        public static var timeSinceLastKey:*=0;

        public static var mousePressed:Boolean=false;

        private static var keyBuffer:Array;
    }
}
