# Multiple Keypresses

**URL:** https://forum.kirupa.com/t/multiple-keypresses/119610
**Category:** Uncategorized
**Created:** [August 16, 2004, 8:55pm UTC](https://forum.kirupa.com/t/multiple-keypresses/119610 "2004-08-16T20:55:03Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![warheart77](https://avatars.discourse-cdn.com/v4/letter/w/71c47a/32.png) [@warheart77](https://forum.kirupa.com/u/warheart77)
#### Post date: [August 16, 2004, 8:55pm UTC](https://forum.kirupa.com/t/multiple-keypresses/119610/1 "2004-08-16T20:55:03Z")

</div>

I did search the forums better this time and found nothing on this particula topic - I’m trying to figure out how to have an event on multiple keypresses rather than just one. For example I have:

* * *

on (keyPress “\<Left\>”) {

loadText=new loadVars();  
loadText.load(“audiophile.txt”);  
loadText.onLoad = function(success) {  
if (success) {  
// trace(success);  
MainBox.html = true;  
MainBox.htmlText = this.audiophileText;  
}  
}  
}

* * *

But rather than just on the “Left” key, I want it to be Left + 1 (holding them down at the same time). How can I do that?

---

<div class="post-metadata">

### Author: ![deQue](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@deQue](https://forum.kirupa.com/u/deQue)
#### Post date: [August 16, 2004, 10:31pm UTC](https://forum.kirupa.com/t/multiple-keypresses/119610/2 "2004-08-16T22:31:49Z")

</div>

You just add an “if” statement inside the “if LEFT” statement:  
if (key is left) {  
if (key is 1) {  
do whatever…  
}  
}

Obviously, this is not the proper code, but I’m sure you can take it from here…

---

<div class="post-metadata">

### Author: ![warheart77](https://avatars.discourse-cdn.com/v4/letter/w/71c47a/32.png) [@warheart77](https://forum.kirupa.com/u/warheart77)
#### Post date: [August 16, 2004, 11:21pm UTC](https://forum.kirupa.com/t/multiple-keypresses/119610/3 "2004-08-16T23:21:42Z")

</div>

That didn’t work… When I changed my coding to that, It said “(” expected…

Ugh. This is so tiring.

---

<div class="post-metadata">

### Author: ![RvGaTe](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rvgate/32/126_2.png) [@RvGaTe](https://forum.kirupa.com/u/RvGaTe)
#### Post date: [August 17, 2004, 12:09am UTC](https://forum.kirupa.com/t/multiple-keypresses/119610/4 "2004-08-17T00:09:44Z")

</div>

make it a movieclip, and use:

```php

onClipEvent (enterFrame) {
	if (Key.isDown(Key.LEFT)) {
		trace("LEFT IS PRESSED");
	}
	if (Key.isDown(Key.RIGHT)) {
		trace("RIGHT IS PRESSED");
	}
	if (Key.isDown(Key.UP)) {
		trace("UP IS PRESSED");
	}
	if (Key.isDown(Key.DOWN)) {
		trace("DOWN IS PRESSED");
	}
}

```

instead of on(key)…

should work…

---

<div class="post-metadata">

### Author: ![warheart77](https://avatars.discourse-cdn.com/v4/letter/w/71c47a/32.png) [@warheart77](https://forum.kirupa.com/u/warheart77)
#### Post date: [August 17, 2004, 12:52am UTC](https://forum.kirupa.com/t/multiple-keypresses/119610/5 "2004-08-17T00:52:34Z")

</div>

Ugh. That only screws up the entire thing. I have no idea what to do here and I’m inches away from freaking out :-/ I tried to turn it into a movie clip, but the thing is it had been working before when I just had it set to on (keyPress) - then when I tried to switch it around, nothing worked! The problem is - what am I supposed to turn into a movie clip - all I want to do is load text into a box when 2 keys are pressed! ahsdjfkgvkdlksjg

---

<div class="post-metadata">

### Author: ![ratbaggy](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@ratbaggy](https://forum.kirupa.com/u/ratbaggy)
#### Post date: [August 17, 2004, 12:58am UTC](https://forum.kirupa.com/t/multiple-keypresses/119610/6 "2004-08-17T00:58:29Z")

</div>

wow…a thank-you for the people who tried to HELP might have be nice

---

<div class="post-metadata">

### Author: ![warheart77](https://avatars.discourse-cdn.com/v4/letter/w/71c47a/32.png) [@warheart77](https://forum.kirupa.com/u/warheart77)
#### Post date: [August 17, 2004, 1:02am UTC](https://forum.kirupa.com/t/multiple-keypresses/119610/7 "2004-08-17T01:02:17Z")

</div>

I’m really sorry - I don’t mean to come off as rude - I really do appreciate it and love all of you, I’m just not thinking straight and having a rough week, but I shouldn’t be taking it at on you wonderful folk - please don’t take me too seriously, and yes, THANK YOU.

---

<div class="post-metadata">

### Author: ![RvGaTe](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rvgate/32/126_2.png) [@RvGaTe](https://forum.kirupa.com/u/RvGaTe)
#### Post date: [August 17, 2004, 4:11pm UTC](https://forum.kirupa.com/t/multiple-keypresses/119610/8 "2004-08-17T16:11:32Z")

</div>

did you solve your problem? that just dozn’t make sence

---

<div class="post-metadata">

### Author: ![claudio](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@claudio](https://forum.kirupa.com/u/claudio)
#### Post date: [August 17, 2004, 4:27pm UTC](https://forum.kirupa.com/t/multiple-keypresses/119610/9 "2004-08-17T16:27:33Z")

</div>

```auto
onKeyDown = function () {
	if (Key.isDown(Key.LEFT) && Key.isDown("1".charCodeAt(0))) {
		loadText = new loadVars();
		loadText.load("audiophile.txt");
		loadText.onLoad = function(success) {
			if (success) {
				// trace(success);
				MainBox.html = true;
				MainBox.htmlText = this.audiophileText;
			}
		};
	}
};
Key.addListener(this);

```

---

<div class="post-metadata">

### Author: ![warheart77](https://avatars.discourse-cdn.com/v4/letter/w/71c47a/32.png) [@warheart77](https://forum.kirupa.com/u/warheart77)
#### Post date: [August 17, 2004, 7:29pm UTC](https://forum.kirupa.com/t/multiple-keypresses/119610/10 "2004-08-17T19:29:45Z")

</div>

Ahhh, thank you Claudio! _Sends yummy foods_

This appears to be working except for:

> **Error** Scene=Scene 1, layer=Text, frame=24:Line 1: Statement must appear within on handler  
> this.onKeyDown = function () {

Total ActionScript Errors: 1 Reported Errors: 1

---

<div class="post-metadata">

### Author: ![warheart77](https://avatars.discourse-cdn.com/v4/letter/w/71c47a/32.png) [@warheart77](https://forum.kirupa.com/u/warheart77)
#### Post date: [August 17, 2004, 7:37pm UTC](https://forum.kirupa.com/t/multiple-keypresses/119610/11 "2004-08-17T19:37:53Z")

</div>

Gah! I took it out of the button’s actionscript and put it on the main timeline and it’s working fine now. Man, it’s always the silliest things :-/ If only Flash would TELL you. But we couldn’t be so lucky! 😛

Thank you immensely Claudio, RvGaTe, and deQue. I really appreciate it!

---

<div class="post-metadata">

### Author: ![samotboy](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@samotboy](https://forum.kirupa.com/u/samotboy)
#### Post date: [August 18, 2004, 4:45am UTC](https://forum.kirupa.com/t/multiple-keypresses/119610/12 "2004-08-18T04:45:05Z")

</div>

Why not try:  
onClipEvent (enterFrame) {  
if (Key.isDown(Key.LEFT) and (Key.isDown(Key.RIGHT)) {  
trace(“Left and right have been pressed?”);  
}  
is what what u wanted?

---

<div class="post-metadata">

### Author: ![warheart77](https://avatars.discourse-cdn.com/v4/letter/w/71c47a/32.png) [@warheart77](https://forum.kirupa.com/u/warheart77)
#### Post date: [August 18, 2004, 6:35pm UTC](https://forum.kirupa.com/t/multiple-keypresses/119610/13 "2004-08-18T18:35:35Z")

</div>

Ugh. Still having issues :-/ Here’s what I have:

> 

onKeyDown = funtion () {  
if (Key.isDown(Key.LEFT) && Key.isDown(“46”.charCodaAt(0))) {  
loadText = new LoadVars();  
loadText.load(“audiophile.txt”);  
loadText.onLoad = function(success) {  
if (success) {  
//trace(success),  
MainBox.html = true;  
MainBox.htmlText = this.audiophileText;  
Key.addListener();  
}  
};  
}  
};

And I have it on the main timeline… I get “this script contains no errors” yet nothing happens when I test it… Does it need to be associated with a button? Or a movie clip?

---

<div class="post-metadata">

### Author: ![claudio](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@claudio](https://forum.kirupa.com/u/claudio)
#### Post date: [August 18, 2004, 11:42pm UTC](https://forum.kirupa.com/t/multiple-keypresses/119610/14 "2004-08-18T23:42:26Z")

</div>

That script is not the one i posted before.
