# \[MX\] 2 keys

**URL:** <https://forum.kirupa.com/t/mx-2-keys/14922>\
**Category:** flash\
**Created:** [March 4, 2003, 1:54pm UTC](https://forum.kirupa.com/t/mx-2-keys/14922 "2003-03-04T13:54:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomoko\_Sasaki](https://avatars.discourse-cdn.com/v4/letter/t/51bf81/32.png) [@Tomoko\_Sasaki](https://forum.kirupa.com/u/Tomoko_Sasaki)\
**Post date:** [March 4, 2003, 1:54pm UTC](https://forum.kirupa.com/t/mx-2-keys/14922/1 "2003-03-04T13:54:02Z")

</div>

in actionscript, Is there a way i can make a coddition happen if 2 keys at once are presssed?

example:  
if (Key.isDown(Key.SHIFT) && (Key.isDown(Key.LEFT) && \_currentframe == 1)) {  
gotoAndPlay(“running\_left”);  
} else if (Key.isDown(Key.RIGHT) && (Key.isDown(Key.RIGHT) && \_currentframe == 1)) {  
gotoAndPlay(“running\_right”);  
}

or can’t i do shift and left/right?

michelle

---

<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:** [March 4, 2003, 2:35pm UTC](https://forum.kirupa.com/t/mx-2-keys/14922/2 "2003-03-04T14:35:45Z")

</div>

I had a go at what you were trying to achieve and came up with this code that seemed to work…

onClipEvent (enterFrame) {  
if ((Key.isDown(Key.SHIFT)) and (Key.isDown (Key.LEFT))) {  
this.gotoAndStop(“running\_left”);  
} else if ((Key.isDown(Key.SHIFT)) and (Key.isDown(Key.RIGHT))) {  
this.gotoAndStop(“running\_right”);  
}  
}

You put that code on the actaul moveclip that i assume you are trying to animate (-:

---

<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:** [March 5, 2003, 4:01am UTC](https://forum.kirupa.com/t/mx-2-keys/14922/3 "2003-03-05T04:01:36Z")

</div>

Another option by using the Key listener…  
This won’t take more CPU power than onEnterFrame handler…

```php
keyDetector = new Object();
keyDetector.onKeyDown = function()
{
	if ((Key.isDown(Key.SHIFT)) && (Key.isDown(Key.LEFT)))
	{
		yourMC.gotoAndStop("running_left");
		trace("running_left");
	}
	else if ((Key.isDown(Key.SHIFT)) && (Key.isDown(Key.RIGHT)))
	{
		yourMC.gotoAndStop("running_right");
		trace("running_right");
	}
};
Key.addListener(keyDetector);

```

Please use [code formatting](http://www.kirupaforum.com/misc.php?action=bbcode#buttons) next time when you post the code… 😉
