0

Key events javascript

Making a game and I wanna use key event press Ctrl key my player shoot a ball. I tried to use keydown and up but it makes him shoot more than one ball in one click. Any suggestions

22nd Nov 2020, 8:55 PM
Khaled ^^ خالد القريشي‎
Khaled ^^ خالد القريشي‎ - avatar
5 Respuestas
+ 1
I'm not 100% sure but I gues keydown should work (if not, add array which will store key down in keydown event and swap on keyup
22nd Nov 2020, 9:01 PM
nicolas turek
nicolas turek - avatar
+ 1
You can make array named for instance keys, than you can in keydown set keys[e.keyCode] to true and in key up false
22nd Nov 2020, 9:16 PM
nicolas turek
nicolas turek - avatar
+ 1
I weren't doing this for long so I'm not really sure about key event properties name
22nd Nov 2020, 9:17 PM
nicolas turek
nicolas turek - avatar
0
nicolas turek I am using keyup and keydown. In key up I set ctrlkey=false. And in keydown I set it again to true. I didn't get the array thing
22nd Nov 2020, 9:06 PM
Khaled ^^ خالد القريشي‎
Khaled ^^ خالد القريشي‎ - avatar
0
It is okay nicolas turek thank you ^^
22nd Nov 2020, 9:17 PM
Khaled ^^ خالد القريشي‎
Khaled ^^ خالد القريشي‎ - avatar