# Key press / release event?

**URL:** <https://forum.kirupa.com/t/key-press-release-event/11330>\
**Category:** Uncategorized\
**Created:** [January 15, 2003, 5:46pm UTC](https://forum.kirupa.com/t/key-press-release-event/11330 "2003-01-15T17:46:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shuga](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@shuga](https://forum.kirupa.com/u/shuga)\
**Post date:** [January 15, 2003, 5:46pm UTC](https://forum.kirupa.com/t/key-press-release-event/11330/1 "2003-01-15T17:46:42Z")

</div>

is there an event you can set like on press’k’ and release’k’ where an event would happen on press of the letter k and then on release of it … kinda like mouse up and down states?

---

<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:** [January 15, 2003, 10:42pm UTC](https://forum.kirupa.com/t/key-press-release-event/11330/2 "2003-01-15T22:42:06Z")

</div>

someone … anyone?

---

<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:** [January 15, 2003, 11:22pm UTC](https://forum.kirupa.com/t/key-press-release-event/11330/3 "2003-01-15T23:22:02Z")

</div>

You can’t do the letter exactly, you can only do the keyCode…

So for “k” (lowercase) it would be…

```auto
_root.onEnterFrame = function() {
	if (Key.isDown(75)) {
		trace("k pressed");
	}
};

```

If you need this for other letters, I wrote a script a while back to help find out. Just copy and paste this code in a blank keyframe in a new document.

```auto
keyListener = new Object();
keyListener.onKeyDown = function() {
	keypressed = Key.getCode();
	trace(keypressed);
};
Key.addListener(keyListener);

```

When you test the movie, you can press a key on the keyboard and it will give you its value.

---

<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:** [January 15, 2003, 11:54pm UTC](https://forum.kirupa.com/t/key-press-release-event/11330/4 "2003-01-15T23:54:22Z")

</div>

I asked more or less the same question here yesterday, but I don’t think I had a positive answer. It should be doable with a bunch of flags though. But I don’t think there’s an event to detect a “release’k”.

pom :cowboy:

---

<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:** [January 16, 2003, 1:57am UTC](https://forum.kirupa.com/t/key-press-release-event/11330/5 "2003-01-16T01:57:13Z")

</div>

Yeah I saw your question Ilyas. And I had no clue as to the answer of that one (if it was the missile one you were talking about).

---

<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:** [January 16, 2003, 4:48am UTC](https://forum.kirupa.com/t/key-press-release-event/11330/6 "2003-01-16T04:48:18Z")

</div>

Hey Ilyas, I kinda got a bit bored as I was sitting here, so I just decided to whip up something in AS.

I was determined to find a way to detect what letter was pressed instead of determing the keycode and going by that.

I think I found it. You are the AS master 😉 so I was wondering if you could look it over for me.

```auto
keyListener = new Object();
keyListener.onKeyDown = function() {
	keyPressed = String.fromCharCode(Key.getCode());
	keypressed == "K" ? trace("k pressed") : trace(keyPressed+" was pressed");
};
Key.addListener(keyListener);

```

Just add that to a frame.

I added the if/else statement in there (i know it is in ?: form, but I got used to that in Javascript and it kinda carried into Flash 🙂 just so you could see how it would look.
