# Keyboard input for game

**URL:** https://forum.kirupa.com/t/keyboard-input-for-game/279048
**Category:** Uncategorized
**Created:** [January 8, 2009, 9:06pm UTC](https://forum.kirupa.com/t/keyboard-input-for-game/279048 "2009-01-08T21:06:52Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![autumnmedia](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@autumnmedia](https://forum.kirupa.com/u/autumnmedia)
#### Post date: [January 8, 2009, 9:06pm UTC](https://forum.kirupa.com/t/keyboard-input-for-game/279048/1 "2009-01-08T21:06:52Z")

</div>

hi i have created a game that uses keyboard input,  
the code below doesnt seem to work when i use keyboard letter such as ‘a’ or ‘k’  
yet will work if i try ‘1’  
when i am in flash and press the letter keys they are still accessing the flash program and not the swf as i can see different things in flash being highlighted behind the swf.  
so what i think i need is a way to make it so that the keyboard letters are activated in the swf  
any help? thanks

```auto
override function keyDownHandler(e:KeyboardEvent):void {
 switch (String.fromCharCode(e.keyCode)){
  case'a' :
   trace("work");
   danceClip.gotoAndStop(2);
   for (var i:uint=removeNum; i<clip; i++) {
    hitTarget = this.getChildByName("arrow"+i);
    if (hitTarget.hitTestPoint(leftSmall.x, leftSmall.y, true)) {
     removeChild(hitTarget);
     removeNum++;
     small=true;
     score+=10;
     energy.gotoAndStop(energy.currentFrame-6);
     perfectClip.gotoAndPlay(2);
     return;
    }
    if (hitTarget.hitTestObject(leftHit) && small==false) {
     removeChild(hitTarget);
     removeNum++;
     score+=5;
     energy.gotoAndStop(energy.currentFrame-2);
     goodClip.gotoAndPlay(2);
     return;
    }
   }
   break;
  case's' :
   danceClip.gotoAndStop(3);
   for (var j:uint=removeNum; j<clip; j++) {
    hitTarget = this.getChildByName("arrow"+j);
 
    if (hitTarget.hitTestPoint(rightSmall.x, rightSmall.y, true)) {
     removeChild(hitTarget);
     removeNum++;
     small=true;
     score+=10;
     energy.gotoAndStop(energy.currentFrame-6);
     perfectClip.gotoAndPlay(2);
     return;
    }
    if (hitTarget.hitTestObject(rightHit) && small==false) {
     removeChild(hitTarget);
     removeNum++;
     score+=5;
     energy.gotoAndStop(energy.currentFrame-2);
     goodClip.gotoAndPlay(2);
     return;
    }
   }
   break;
  case 'd' :
   danceClip.gotoAndStop(4);
   for (var k:uint=removeNum; k<clip; k++) {
    hitTarget = this.getChildByName("arrow"+k);
    if (hitTarget.hitTestPoint(upSmall.x, upSmall.y, true)) {
     removeChild(hitTarget);
     removeNum++;
     small=true;
     score+=10;
     energy.gotoAndStop(energy.currentFrame-6);
     perfectClip.gotoAndPlay(2);
     return;
    }
    if (hitTarget.hitTestObject(upHit) && small==false) {
     removeChild(hitTarget);
     removeNum++;
     score+=5;
     energy.gotoAndStop(energy.currentFrame-2);
     goodClip.gotoAndPlay(2);
     return;
    }
   }
   break;
  case 'f' :
   danceClip.gotoAndStop(5);
   for (var l:uint=removeNum; l<clip; l++) {
    hitTarget = this.getChildByName("arrow"+l);
    if (hitTarget.hitTestPoint(downSmall.x, downSmall.y, true)) {
     removeChild(hitTarget);
     removeNum++;
     small=true;
     score+=10;
     energy.gotoAndStop(energy.currentFrame-6);
     perfectClip.gotoAndPlay(2);
     return;
    }
    if (hitTarget.hitTestObject(downHit) && small==false) {
     removeChild(hitTarget);
     removeNum++;
     score+=5;
     energy.gotoAndStop(energy.currentFrame-2);
     goodClip.gotoAndPlay(2);
     return;
    }
   }
   break;
  default :
   break;
 }
}

```
