# How to detect fast key presses?

**URL:** https://forum.kirupa.com/t/how-to-detect-fast-key-presses/252820
**Category:** Uncategorized
**Created:** [February 24, 2008, 1:58am UTC](https://forum.kirupa.com/t/how-to-detect-fast-key-presses/252820 "2008-02-24T01:58:01Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ryan123](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@ryan123](https://forum.kirupa.com/u/ryan123)
#### Post date: [February 24, 2008, 1:58am UTC](https://forum.kirupa.com/t/how-to-detect-fast-key-presses/252820/1 "2008-02-24T01:58:01Z")

</div>

I am trying to make a game that requires the user to input a lot of different keys in a very short amount of time.

If I use something like this:

setInterval(function () {  
trace("The ASCII code for the last key typed is: "+Key.getAscii());  
},100);

it will display trace many times, but I only want it once for each key press.

If I do this

[COLOR=#993300]var[/COLOR] keyListener:[COLOR=#993300]Object[/COLOR] = [COLOR=#993300]new[/COLOR] [COLOR=#993300]Object[/COLOR]COLOR=#000000[/COLOR];  
keyListener.[COLOR=#993300]onKeyDown[/COLOR] = [COLOR=#993300]function[/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#993300]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]"The ASCII code for the last key typed is: "[/COLOR]+[COLOR=#993300]Key[/COLOR].[COLOR=#993300]getAscii[/COLOR]COLOR=#000000[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000]}[/COLOR];  
[COLOR=#993300]Key[/COLOR].[COLOR=#993300]addListener[/COLOR]COLOR=#000000[/COLOR];It’s way too slow, and only some of my key presses get traced.
