View Full Version : Keys?
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.:confused::confused::confused::confused::confused:
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.
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.
How do I do that:confused::confused::confused:
A simple example ;)
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);
}
};
jackbenimble4
02-03-2008, 04:28 PM
Here's some resources:
w3cschools onkeyup event information (http://www.w3schools.com/jsref/jsref_onkeyup.asp)
Table of key codes (http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.