isaac19030
Coder
After posting last week, I decided to isolate the code to very basic logic and I still have the same problem.
With the attached code I cannot get the "D", "W" and "Spacebar" keys to fire simultaneously. It works with "A"
, "W" and "Spacebar"...
How can this be? There must be something wrong with my keyboard perhaps.
Any Ideas would be greatly appreciated. Thanks!
With the attached code I cannot get the "D", "W" and "Spacebar" keys to fire simultaneously. It works with "A"
Code:
<!DOCTYPE html>
<html>
<body>
<script>
let test = function(input){console.log(input)};
let keyPress = {};
let testKeys = function(){
//move left
if (keyPress.a && !keyPress.d){
//test('A, Left');
};
//move right
if (keyPress.d && !keyPress.a){
//test('D, Right');
};
//run
if(keyPress[' ']){
//test('Spacebar, Run');
};
//jump
if(keyPress.w){
//test('W, Jump');
};
if(keyPress.a && keyPress.w && keyPress[' ']){
test('jump running to the left');
};
//I Cannot get this to display
if(keyPress.d && keyPress.w && keyPress[' ']){
test('jump running to the right');
};
requestAnimationFrame(testKeys);
};
testKeys();
window.addEventListener('keydown', keyDownListener);
function keyDownListener(event) {
keyPress[event.key] = true;
};
window.addEventListener('keyup', keyUpListener);
function keyUpListener(event) {
keyPress[event.key] = false;
};
</script>
</body>
</html>
How can this be? There must be something wrong with my keyboard perhaps.
Any Ideas would be greatly appreciated. Thanks!
Last edited: