# Key down

**URL:** https://forum.kirupa.com/t/key-down/118350
**Category:** Uncategorized
**Created:** [August 4, 2004, 5:58pm UTC](https://forum.kirupa.com/t/key-down/118350 "2004-08-04T17:58:53Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![saad](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@saad](https://forum.kirupa.com/u/saad)
#### Post date: [August 4, 2004, 5:58pm UTC](https://forum.kirupa.com/t/key-down/118350/1 "2004-08-04T17:58:53Z")

</div>

hey I cant figure out why this isnt working I have only frame which I put this code into

if (Key.isDown(Key.RIGHT)){  
trace(“key down”);  
}

nothing happens, whats happening?

---

<div class="post-metadata">

### Author: ![eyezberg](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@eyezberg](https://forum.kirupa.com/u/eyezberg)
#### Post date: [August 4, 2004, 6:11pm UTC](https://forum.kirupa.com/t/key-down/118350/2 "2004-08-04T18:11:33Z")

</div>

better to use a listener object, did you have a look at the flash help & reference files?

---

<div class="post-metadata">

### Author: ![saad](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@saad](https://forum.kirupa.com/u/saad)
#### Post date: [August 4, 2004, 6:26pm UTC](https://forum.kirupa.com/t/key-down/118350/3 "2004-08-04T18:26:29Z")

</div>

no, why doesnt that work. And how would a listener work to accomplish this?

---

<div class="post-metadata">

### Author: ![claudio](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@claudio](https://forum.kirupa.com/u/claudio)
#### Post date: [August 4, 2004, 6:26pm UTC](https://forum.kirupa.com/t/key-down/118350/4 "2004-08-04T18:26:45Z")

</div>

It doesn’t work because that condition is checked only once as the movie starts.  
So if you hold the ‘right’ key and run the movie, it will detect the keypress.

As eyezberg suggested, you have to make the Key object continuously listen to your keypresses. Something like this:

```auto
this.onKeyDown = function() {
	if (Key.isDown(Key.RIGHT)) {
		trace("key down");
	}
};
Key.addListener(this);

```

---

<div class="post-metadata">

### Author: ![saad](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@saad](https://forum.kirupa.com/u/saad)
#### Post date: [August 4, 2004, 6:30pm UTC](https://forum.kirupa.com/t/key-down/118350/5 "2004-08-04T18:30:11Z")

</div>

Thanks

---

<div class="post-metadata">

### Author: ![claudio](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@claudio](https://forum.kirupa.com/u/claudio)
#### Post date: [August 4, 2004, 6:33pm UTC](https://forum.kirupa.com/t/key-down/118350/6 "2004-08-04T18:33:25Z")

</div>

Welcome

---

<div class="post-metadata">

### Author: ![eyezberg](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@eyezberg](https://forum.kirupa.com/u/eyezberg)
#### Post date: [August 4, 2004, 9:21pm UTC](https://forum.kirupa.com/t/key-down/118350/7 "2004-08-04T21:21:55Z")

</div>

claudio is too helpfull sometimes… 🙂  
let people code their own, your detailed intro should’ve been enough  
(“It doesn’t work because that condition is checked only once as the movie starts.  
So if you hold the ‘right’ key and run the movie, it will detect the keypress…you have to make the Key object continuously listen to your keypresses”)  
else they’ll never learn 😉
