# Help with Keyboard actions

**URL:** <https://forum.kirupa.com/t/help-with-keyboard-actions/111375>\
**Category:** Uncategorized\
**Created:** [May 26, 2004, 11:53am UTC](https://forum.kirupa.com/t/help-with-keyboard-actions/111375 "2004-05-26T11:53:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![enterspacecapsu](https://avatars.discourse-cdn.com/v4/letter/e/67e7ee/32.png) [@enterspacecapsu](https://forum.kirupa.com/u/enterspacecapsu)\
**Post date:** [May 26, 2004, 11:53am UTC](https://forum.kirupa.com/t/help-with-keyboard-actions/111375/1 "2004-05-26T11:53:41Z")

</div>

Hi guys, im having a headache time trying to work out how this would work.  
Ive got a movie clip with the variable “\_root.bla.bla”(frame 1 is stopped while the rest of the frame doesnt stop in this movie clip). I want to add a actionscript that when i hold onto a keyboard button like up arrow, it will start playing from frame 2 onwards and when i let go of it, it will stop playing and immediately return to frame 1.

Can anyone please enlighten me on this?

---

<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:** [May 26, 2004, 7:58pm UTC](https://forum.kirupa.com/t/help-with-keyboard-actions/111375/2 "2004-05-26T19:58:39Z")

</div>

```auto
//define onKeyDown event handler
this.onKeyDown = function() {
	//if the up arrow is pressed
	if (Key.isDown(Key.UP)) {
		//play
		this.play();
	}
};
//define onKeyUp event handler
this.onKeyUp = function() {
	//if the up arrow is not pressed
	if (!Key.isDown(Key.UP)) {
		//send playhead to frame 1 and stop
		this.gotoAndStop(1);
	}
};
//register object as listener for the Key object
Key.addListener(this);

```

---

<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:** [May 27, 2004, 10:13am UTC](https://forum.kirupa.com/t/help-with-keyboard-actions/111375/3 "2004-05-27T10:13:06Z")

</div>

hey awesome dude that worked great, thanks a lot.  
Oh and BTW, there should be a onClipEvent (enterFrame) bracketed on the code, but anyway the code rocks

---

<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:** [May 28, 2004, 7:22am UTC](https://forum.kirupa.com/t/help-with-keyboard-actions/111375/4 "2004-05-28T07:22:08Z")

</div>

No problem. 🙂

And no, you don’t need to put the code within an [font=courier new]enterFrame[/font] event, the code was supposed to be on the frame actions rather than the symbol actions; but if you want to put it on the symbol actions, use the [font=courier new]load[/font] event instead. 😉

```auto
onClipEvent (load) {
	this.onKeyDown = function() {
		if (Key.isDown(Key.UP)) {
			this.play();
		}
	};
	this.onKeyUp = function() {
		if (!Key.isDown(Key.UP)) {
			this.gotoAndStop(1);
		}
	};
	Key.addListener(this);
}

```
