You cannot control the keyboard with actionscript, but you can mimic what the keyboard keys do by programming the buttons to take the same actions as what you code for the keys. If you code the right arrow keyboard key to make something move right, then you use that same moving right code for the button that you want to make things move right.
Example...
var goLeft:Boolean = false; // create goRight, goUp, goDown as well for the other controls
function hearKeyDown(yourEvent:KeyboardEvent):void{ // you can include all the keys in here
if (yourEvent.keyCode==Keyboard.RIGHT){ goRight = true; }
stage.addEventListener(Event.ENTER_FRAME, moveObject);
}
function hearKeyUp(yourEvent:KeyboardEvent):void{ // you can include all the keys in here
if (yourEvent.keyCode==Keyboard.RIGHT){ goRight = false; }
stage.removeEventListener(Event.ENTER_FRAME, moveObject);
}
function hearMouseDown(yourEvent:MouseEvent):void{ // you can include all the buttons in here
if (yourEvent.currentTarget==btn1){ goLeft = true; }
stage.addEventListener(Event.ENTER_FRAME, moveObject);
}
function hearMouseUp(yourEvent:MouseEvent):void{ // you can include all the buttons in here
if (yourEvent.currentTarget==btn1){ goLeft = false; }
stage.removeEventListener(Event.ENTER_FRAME, moveObject);
}
function moveObject(evt:Event):void { // share this for all the keys and buttons
if (goLeft){ object_mc.x-=5 };
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, hearKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, hearKeyUp);
btn1.addEventListener(MouseEvent.MOUSE_DOWN, hearMouseDown);
btn1.addEventListener(MouseEvent.MOUSE_UP, hearMouseUp);