# onKeyDown question

**URL:** <https://forum.kirupa.com/t/onkeydown-question/61976>\
**Category:** flash\
**Created:** [August 23, 2004, 8:47pm UTC](https://forum.kirupa.com/t/onkeydown-question/61976 "2004-08-23T20:47:39Z")\
**Posts on this page:** 1\
**Showing post:** 8

<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:** [August 26, 2004, 7:36pm UTC](https://forum.kirupa.com/t/onkeydown-question/61976/8 "2004-08-26T19:36:37Z")

</div>

Hello!  
Ok, I did what you said and it still doesn’t work. ☹ I will write the code for my onKeyDown function here but I don’t think it’s easy to understand without a lot of details (and my comments are in french…)  
Anyway here it is with the stuff you told me to add :

var myListener = new Object();  
myListener.onKeyDown = function () {  
if(x!=2){  
if(\_root[“m”+cote].\_visible == false){  
//Si la lettre tapée par l’usager est égale à celle du bloc  
if (String.fromCharCode(Key.getAscii()) == \_root[“b”+cote+bloc].lettre.text) {  
//Augmente la vitesse de la balle  
Intervalle = 30;  
for(i=1;i\<=4;i++){  
for(j=1;j\<=\_global.nbBloc[i-1];j++){  
if(String.fromCharCode(Key.getAscii()) == \_root[“b”+i+j].lettre.text) {  
//Soulève tous les blocs contenant la lettre tapée  
\_root[“b”+i+j].action.gotoAndPlay(“c”+i+j+“s”);  
}  
else  
{  
\_root[“b”+cote+bloc].action.gotoAndPlay(“v”+cote+bloc+“b”);  
\_root[“b”+i+j].action.gotoAndPlay(“c”+i+j+“b”);  
}  
}  
}  
//Soulève le bloc vert contenant la lettre tapée  
\_root[“b”+cote+bloc].action.gotoAndPlay(“v”+cote+bloc+“s”);  
}  
else{  
//Si la lettre tapée par l’usager n’est pas égale à celle du bloc  
for(i=1;i\<=4;i++){  
for(j=1;j\<=\_global.nbBloc[i-1];j++){  
if (String.fromCharCode(Key.getAscii()) == \_root[“b”+i+j].lettre.text){  
//Soulève tous les blocs contenant la lettre tapée  
\_root[“b”+i+j].action.gotoAndPlay(“c”+i+j+“s”);  
}  
else  
{  
//Mets les bloc à “bas”  
\_root[“b”+i+j].action.gotoAndPlay(“c”+i+j+“b”);  
}  
//Si on tape la barre d’espacement  
if (Key.getAscii() == 32){  
//Met tous les blocs à “bas”  
\_root[“b”+i+j].action.gotoAndPlay(“c”+i+j+“b”);  
}  
//Met le bloc vert à “bas”  
\_root[“b”+cote+bloc].action.gotoAndPlay(“v”+cote+bloc+“b”);  
}  
}  
}  
}  
x = 2;  
}  
}  
myListener.onKeyUp = function () {  
x=1;  
}  
Key.addListener(myListener);

Hope it’s useful and that you could understand it.  
Thanks!

---

_[View the full topic](https://forum.kirupa.com/t/onkeydown-question/61976)._
