# Trapping the Escape key

**URL:** https://forum.kirupa.com/t/trapping-the-escape-key/6470
**Category:** flash
**Created:** [October 8, 2002, 8:06am UTC](https://forum.kirupa.com/t/trapping-the-escape-key/6470 "2002-10-08T08:06:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![JohnLawton](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnlawton/32/42_2.png) [@JohnLawton](https://forum.kirupa.com/u/JohnLawton)
#### Post date: [October 8, 2002, 8:06am UTC](https://forum.kirupa.com/t/trapping-the-escape-key/6470/1 "2002-10-08T08:06:03Z")

</div>

Hi

I am creating a software product demonstrator. The software uses the Escape key to let users get out of menus - crap I know, but that’s the way they do it!!

My problem is that I want Flash MX to look out for the Escape key being hit within my demonstrator and then go to another frame when it is hit.

Any ideas/sample code would be very welcome

Thanks

John 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 8, 2002, 8:34am UTC](https://forum.kirupa.com/t/trapping-the-escape-key/6470/2 "2002-10-08T08:34:51Z")

</div>

Well, it just goes to show that a little struggle through the help files sometimes pays off!!

\_root.onEnterFrame = function() {  
if (key.isDown(key.ESCAPE)) {  
gotoAndPlay(“EscapeHit”);  
}  
};

will do the job from that frame on. If anyone has any smarter ways of doing it please let me know.

I hope this can help someone else one day!

Cheers

John 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [October 8, 2002, 1:04pm UTC](https://forum.kirupa.com/t/trapping-the-escape-key/6470/3 "2002-10-08T13:04:50Z")

</div>

:-\ It doesn’t work for me. I can trap the space bar, any letter, but not escape…

Anyway, you can check if escape was pressed only when the user presses a button, it will be less processor intensive:

```auto
_root.onKeyDown = function() {
	if (key.isDown(key.ESCAPE)) {
		trace("EscapeHit");
	}
};
Key.addListener(_root);

```

pom 😏
