# Key Press

**URL:** <https://forum.kirupa.com/t/key-press/18315>\
**Category:** flash\
**Created:** [April 15, 2003, 2:48pm UTC](https://forum.kirupa.com/t/key-press/18315 "2003-04-15T14:48:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mystee](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@mystee](https://forum.kirupa.com/u/mystee)\
**Post date:** [April 15, 2003, 2:48pm UTC](https://forum.kirupa.com/t/key-press/18315/1 "2003-04-15T14:48:44Z")

</div>

Hi,

I’m trying to use key press to “move” my character in flash…instead of the one like [http://www.kirupa.com/developer/mx/movement\_keys.htm](http://www.kirupa.com/developer/mx/movement_keys.htm)  
…what I want to achieve is to use the left and right keys to rotate the object…when I press right…it turns clockwise…and when i press left…it turn anti-clockwise…

So…anyone knows how it could be done?? :hair:

---

<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:** [April 15, 2003, 3:04pm UTC](https://forum.kirupa.com/t/key-press/18315/2 "2003-04-15T15:04:40Z")

</div>

There might be better ways as I’m no ASguru, but you could do it like this:

supposed the targetmc has an instance name of myMC, put this in the main timeline:

```auto

speed = 2;

_root.onEnterFrame = function(){
	if(Key.isDown(Key.RIGHT)) {
		_root.myMC._rotation += speed;
	} 
	else if (Key.isDown(Key.LEFT)) {
		_root.myMC._rotation -= speed;
	}
}

```

---

<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:** [April 16, 2003, 6:56am UTC](https://forum.kirupa.com/t/key-press/18315/3 "2003-04-16T06:56:30Z")

</div>

Thanks…the rotation works…but there’s a slightly problem here…

For example…when my MC has rotated 90 clockwise…I would wan it to move to the right using my right key…and not rotate even more…how can this be acheived?

---

<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:** [April 16, 2003, 7:17am UTC](https://forum.kirupa.com/t/key-press/18315/4 "2003-04-16T07:17:46Z")

</div>

try this:

```auto

speed = 4;

_root.onEnterFrame = function(){
	if(Key.isDown(Key.RIGHT)) {
		if(_root.myMC._rotation >= 90){
			_root.myMC.rotation = 90;
			_root.myMC._x += speed;
		}
		else _root.myMC._rotation += speed;
	} 
	else if (Key.isDown(Key.LEFT)) {
		if(_root.myMC._rotation <= -90){
			_root.myMC.rotation = -90;	
			_root.myMC._x -= speed;	
		}
		else _root.myMC._rotation -= speed;
	}
}

```

I hope this is what you’re looking for?

---

<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:** [April 16, 2003, 5:26pm UTC](https://forum.kirupa.com/t/key-press/18315/5 "2003-04-16T17:26:21Z")

</div>

it doesn’t seem to work…

actually…what i gave was an example… what if I jus want the right and left keys to rotate…and the up key to move forward and down key to reverse?

Eg: If i had rotate my MC 90 degrees clockwise, how to get it to move right (which is forward) using the up key?

---

<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:** [April 16, 2003, 5:33pm UTC](https://forum.kirupa.com/t/key-press/18315/6 "2003-04-16T17:33:39Z")

</div>

It works actually…but that’s not what i want.

What I actually want is that user can freely navigate the character…using up and down keys to move forward and reverse, left and right keys to rotate…=|

---

<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:** [April 16, 2003, 5:42pm UTC](https://forum.kirupa.com/t/key-press/18315/7 "2003-04-16T17:42:06Z")

</div>

try making the object a movie clip, have it play certain frames when the user presses left, as in  
onKeyPress(\<left\>) {  
gotoAndPlay(10);  
}  
(for example)…  
and when they press up and down, the movie clip can move up and down…and i’m pretty sure you know how to do that

---

<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:** [April 16, 2003, 6:05pm UTC](https://forum.kirupa.com/t/key-press/18315/8 "2003-04-16T18:05:49Z")

</div>

play certain frames? but that’s not what i wanted. Instead of preset animation, I want the MC to move according to the user key presses…

---

<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:** [April 16, 2003, 6:11pm UTC](https://forum.kirupa.com/t/key-press/18315/9 "2003-04-16T18:11:21Z")

</div>

ya i get it…and it’s possible with a mc…but try it with the code first…it’ll probably be less of a headache

---

<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:** [April 17, 2003, 10:39am UTC](https://forum.kirupa.com/t/key-press/18315/10 "2003-04-17T10:39:34Z")

</div>

hmm…how can i get this key press effect using AS?

[http://www.jump-tomorrow.com/](http://www.jump-tomorrow.com/)

Pls help…i’m still a newbie…=|
