View Full Version : Javascript Keypress Function
schnitzel_21st
02-27-2004, 12:43 AM
hay, i was wondering if someone would be able to explain to me how to call a function if you press, for example, the A key. ( Not if you type it in a text box )
Thanks, Nigel =)
Willy Duitt
02-27-2004, 01:04 AM
The answer to your question begins here (http://www.htmlforums.com/showthread.php?s=&threadid=35345).
Follow the links....
.....Willy
schnitzel_21st
02-27-2004, 05:28 PM
After looking at that, i came up with this:
<body onkeypress="press()">
<SCRIPT language=JavaScript>
<!--
// keyCode '100' = 'D'
function press() {
if (event.keyCode==100){
alert('hello');
}
}
// -->
</SCRIPT>
</body>
agent002
02-28-2004, 04:28 AM
here (http://www.w3schools.com/html/html_asciiref.asp) is an ascii reference, should also explain the keyCodes pretty well.
schnitzel_21st
03-01-2004, 12:03 AM
mmm, very handy =) pity i spent a good half hour working them out my self =)
P.S. Agent002: How did you get those flash like mixed color links in your signature?
agent002
03-01-2004, 07:58 AM
Originally posted by schnitzel_21st
P.S. Agent002: How did you get those flash like mixed color links in your signature?
I just use the [color=color here]text here[/color] vbCode to give each letter a different color... it goes from #005000, #006000, #007000 etc. up to #00C000 and down again, back and forth.
schnitzel_21st
03-01-2004, 07:06 PM
oh right, you just do each letter individually =) gud az:P
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.