Hey how would I make something like if I pressed the up kep it would make an alert and down key would make an imag.. etc.![]()
Hey how would I make something like if I pressed the up kep it would make an alert and down key would make an imag.. etc.![]()
Jeremy | jfein.net
Look for the window.onkeydown, window.onkeyup events
No but what I want is if you press the up, down, right, left keys to make an alert or something.
Jeremy | jfein.net
Ok, I thought so and posted the above message. You should assign a function to the window.onkeyup or window.onkeydown events and then handle the key code inside that function and respond to the keycodes you want.
A simple example
Code:window.onkeydown=function(e) { var key = e ? e.which : window.event.keyCode; switch(key) { case 27: alert("You cannot escape from me!"); break; case 13: alert("You have pressed enter, right?"); break; default: alert("Pressed key's code is: " + key); } };
Here's some resources:
w3cschools onkeyup event information
Table of key codes
Bookmarks