+ 1

Make a key perform an action when preseed?

Hey Sololearn community! I was trying to make a game in javascript but could not figure out how to make a command run when a key is pressed. Example: When the ‘A’ key is pressed, execute an alert function. Thanks!

19th Nov 2017, 5:52 PM
AnonymousPug 55
AnonymousPug 55 - avatar
4 RĂ©ponses
+ 1
Qyther i tried it and it did not work for me :(
19th Nov 2017, 9:24 PM
AnonymousPug 55
AnonymousPug 55 - avatar
0
ooh that is simple, just add this: HTML < <input type="text" onkeydown="checker(event)"> > JS < function checker(e) { var key = e.keyCode; if (key === 229) { alert("A key pressed!"); } } EDIT: The keycode isn't actually 65! its 229!
19th Nov 2017, 6:48 PM
Qyther
Qyther - avatar
0
heya! look at the edit
19th Nov 2017, 6:56 PM
Qyther
Qyther - avatar
20th Nov 2017, 7:25 AM
Qyther
Qyther - avatar