I'm trying to execute two javascript functions:
<body onkeydown="movimentation()">
<script>
function movimentation(){
var key=event.key;
if(key==='8'){
up2();
console.log("the key pressioned is " + key);
};
if(key==="5"){
down2();
console.log("the key pressioned is " + key);
};
if(key==="6" ){
rigth2();
console.log("the key pressioned is " + key);
};
if(key==="4"){
left2();
console.log("the key pressioned is " + key);
};if(key==="w"){
up1();
console.log("the key pressioned is " + key);
};
if(key==="s" ){
down1();
console.log("the key pressioned is " + key);
};
if(key==="d"){
rigth1();
console.log("the key pressioned is " + key);
};
if(key==="a"){
left1();
console.log("the key pressioned is " + key);
}else{};
}
function p2movimentation(key){
if(key==='8'){
up2();
console.log("the key pressioned is " + key);
};
if(key==="5" && p2x<98){
down2();
console.log("the key pressioned is " + key);
};
if(key==="6" ){
rigth2();
console.log("the key pressioned is " + key);
};
if(key==="4"){
left2();
console.log("the key pressioned is " + key);
}else{};
};
function p1movimentation(key){
if(key==="w"){
up1();
console.log("the key pressioned is " + key);
};
if(key==="s"){
down1();
console.log("the key pressioned is " + key);
};
if(key==="d"){
rigth1();
console.log("the key pressioned is " + key);
};
if(key==="a" ){
left1();
console.log("the key pressioned is " + key);
}else{};
};
(up1(),down1(),rigth1() and left1() moviment player 1 and up2(),down2(),rigth2() and left2() moviment player 2)
But the activation of the first function prevent the activation of the second one.
I would love that the two functions are executed simultaneously.