Click to See Complete Forum and Search --> : Type G key and output numbers . . .


Code One
05-15-2003, 03:34 AM
Hey folks,
Havent heard from you guys in a while, I've been totally busy working with a client and going to school and working full time and it all kinda gets distracting. Anyway . . . I was wondering how to be able to do this:

I would like to capture a key on my keyboard for example the "B key". When I type the "B key" I would like for the output to not be the letter B, but I would like for it to be a number of my choice for example:

User types the B button on their keyboard and the output is something like 100.

Formula: Press + B key = 100.

Got it? I bet you do!

All help is appreciated!

Code One

Gollum
05-15-2003, 04:10 AM
Something like this should do...

<html>
<head>
<script language="Javascript">
function KeyDown(oInput, e)
{
if ( e.keyCode == 71 ) // 'g'
{
oInput.value += '71';
e.returnValue = false; // for IE
}
}
</script>
</head>
<body>
<input type=text name=theInput onkeydown="KeyDown(this, event);">
</body>
</html>

Note: I haven't handled the Netscape event model here but it's not too hard to add