# Problem controlling player movement with keyboard

**URL:** <https://forum.kirupa.com/t/problem-controlling-player-movement-with-keyboard/233676>\
**Category:** flash\
**Created:** [July 25, 2007, 9:53pm UTC](https://forum.kirupa.com/t/problem-controlling-player-movement-with-keyboard/233676 "2007-07-25T21:53:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wintergreen](https://avatars.discourse-cdn.com/v4/letter/w/71c47a/32.png) [@wintergreen](https://forum.kirupa.com/u/wintergreen)\
**Post date:** [July 25, 2007, 9:53pm UTC](https://forum.kirupa.com/t/problem-controlling-player-movement-with-keyboard/233676/1 "2007-07-25T21:53:06Z")

</div>

I’m making a side scroller game and want to move the player across the screen using the arrow keys on the keyboard. I am able to move him fine, but he always seems to move over once, pause and then continue moving until i let go of the key. I want to get rid of that little pause that keeps occuring.

I tried to minimalize the code as much as I could and I was sure that having a loop to keep the player moving until the key was released would make it smooth, but the lag is still there.

Any ideas on why this happens or how I can move the player smoothly would be much appreciated, thanks!

```auto
var keyNowUp:Boolean = true;
stage.addEventListener(KeyboardEvent.KEY_DOWN, movePlayer);
stage.addEventListener(KeyboardEvent.KEY_UP, stopPlayer);

function movePlayer(event:KeyboardEvent)
{
    keyNowUp = false;
    do {
        player.x += 10;
    } while(keyNowUp = false)
}

function stopPlayer(event:KeyboardEvent)
{
    keyNowUp = true;    
}

```
