# \[AS2\] Lag on key press

**URL:** <https://forum.kirupa.com/t/as2-lag-on-key-press/324898>\
**Category:** programming\
**Created:** [September 14, 2011, 4:56pm UTC](https://forum.kirupa.com/t/as2-lag-on-key-press/324898 "2011-09-14T16:56:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sev3n](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@sev3n](https://forum.kirupa.com/u/sev3n)\
**Post date:** [September 14, 2011, 4:56pm UTC](https://forum.kirupa.com/t/as2-lag-on-key-press/324898/1 "2011-09-14T16:56:20Z")

</div>

[COLOR=#333233]Hi guys. I’m working on a game in AS 2, but have encountered a problem - the game gets steadily more laggy as you progress through the levels, but the lag only occurs when a key is pressed (usually frequent presses or keys being held down - in particular, the arrow keys to move the player).[/COLOR]  
[COLOR=#333233]  
[/COLOR]  
[COLOR=#333233]To move the player:

[/COLOR]

```auto
[COLOR=#333233]if(keyup == true && keyleft == false && keyright == false && keydown == false) {[/COLOR]
[COLOR=#333233] _root.hero._y -= moveup;[/COLOR]

```

[COLOR=#333233]  
And I’m using a function to determine key down:[/COLOR]  
[COLOR=#333233]  
[/COLOR]

```auto
[COLOR=#333233]keyListener.onKeyDown = function() {[/COLOR]
[COLOR=#333233]if (keyisdownvar(keyupdown) && !keyisdownvar(keyleftdown) && !keyisdownvar(keyrightdown) && !keyisdownvar(keydowndown)) {[/COLOR]
[COLOR=#333233] keyup = true;[/COLOR]
[COLOR=#333233] keyleft = false;[/COLOR]
[COLOR=#333233] keydown = false;[/COLOR]
[COLOR=#333233] keyright = false;[/COLOR]
}
[COLOR=#333233] }[/COLOR]

```

[COLOR=#333233]  
There’s nothing wrong with the code per se - I was just wondering if there is a more efficient way of doing this that will work better towards reducing lag?

Thanks guys.[/COLOR]
