keydown/keyup vs. keypress keyCodes 
Author Message
 keydown/keyup vs. keypress keyCodes

I have discovered that the keyCodes for the keydown or keyup events do
not necessarily match the keyCode for the keypress event.  For
example, the numeric keypad's minus key has a value of 109 for the
keydown/keyup but a value of 45 for the keypress.  The minus key on
the row above the QWER row has corresponding values of 189 and 45
respectively.  45 is the ASCII value for a minus.  

Just to make matters *really* confusing, the keydown/keyup keyCode for
the Insert key is 45.  (AFAIK, there is no keyPress event for the
Insert key.)

Netscape has 45 for all three events.  For the spacebar, IE has a 32
for all three values.

I would like to determine what key is pressed; i.e., I would like to
blur, if a text field is filled, but do *not* want to blur if merely
an arrow key is pressed.

I would appreciate anyone pointing me in the right direction.
Rich Blackburn



Tue, 20 Nov 2001 03:00:00 GMT  
 keydown/keyup vs. keypress keyCodes

Quote:

>I have discovered that the keyCodes for the keydown or keyup events do
>not necessarily match the keyCode for the keypress event.

Hi Rich,

This is probably because onKeyUp and onKeyDown give you the hardware scan
code for the key, whilst onKeyPress gives you the Unicode number for the
character generated by that key. This lets you differentiate between keypad
keys and 'normal' keys, for example.

Admittedly, the Internet Explorer DOM documentation doesn't really make this
all that clear...

Peter

--

    No longer laying about at home - what a bummer, dude! :-)
JScript FAQ: http://www.netspace.net.au/~torrboy/code/jscriptfaq/



Thu, 22 Nov 2001 03:00:00 GMT  
 keydown/keyup vs. keypress keyCodes
Thanks Peter,
This makes perfect sense.  I will adjust my code accordingly!  I was
unable to find this clarification in any of the many books I have or
the tons of websites I have visited.  

BTW, I visited your website
http://www.netspace.net.au/~torrboy/code/jscriptfaq/ per the URL at
the bottom of your response  and got some lightbulbs turned on.  For
example, you did a great job of separating JScript, JavaScript, DOM,
etc.  Thanks for that, too.  (I highly recommend it.)

Rich

On Sun, 6 Jun 1999 17:34:31 +1000, "Peter J. Torr"

Quote:


>>I have discovered that the keyCodes for the keydown or keyup events do
>>not necessarily match the keyCode for the keypress event.

>Hi Rich,

>This is probably because onKeyUp and onKeyDown give you the hardware scan
>code for the key, whilst onKeyPress gives you the Unicode number for the
>character generated by that key. This lets you differentiate between keypad
>keys and 'normal' keys, for example.

>Admittedly, the Internet Explorer DOM documentation doesn't really make this
>all that clear...

>Peter

>--

>    No longer laying about at home - what a bummer, dude! :-)
>JScript FAQ: http://www.netspace.net.au/~torrboy/code/jscriptfaq/



Thu, 22 Nov 2001 03:00:00 GMT  
 keydown/keyup vs. keypress keyCodes
I was trying to come up with a character counter for an input area and
it worked fine EXCEPT for backspacing --- I couldn't locate the proper
value for backspace -- do you know it this key actually fires
keyup/down or keypress?



Quote:
> Thanks Peter,
> This makes perfect sense.  I will adjust my code accordingly!  I was
> unable to find this clarification in any of the many books I have or
> the tons of websites I have visited.

> BTW, I visited your website
> http://www.netspace.net.au/~torrboy/code/jscriptfaq/ per the URL at
> the bottom of your response  and got some lightbulbs turned on.  For
> example, you did a great job of separating JScript, JavaScript, DOM,
> etc.  Thanks for that, too.  (I highly recommend it.)

> Rich

> On Sun, 6 Jun 1999 17:34:31 +1000, "Peter J. Torr"




- Show quoted text -

Quote:
> >>I have discovered that the keyCodes for the keydown or keyup events
do
> >>not necessarily match the keyCode for the keypress event.

> >Hi Rich,

> >This is probably because onKeyUp and onKeyDown give you the hardware
scan
> >code for the key, whilst onKeyPress gives you the Unicode number for
the
> >character generated by that key. This lets you differentiate between
keypad
> >keys and 'normal' keys, for example.

> >Admittedly, the Internet Explorer DOM documentation doesn't really
make this
> >all that clear...

> >Peter

> >--

> >    No longer laying about at home - what a bummer, dude! :-)
> >JScript FAQ: http://www.netspace.net.au/~torrboy/code/jscriptfaq/

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


Tue, 27 Nov 2001 03:00:00 GMT  
 keydown/keyup vs. keypress keyCodes
Hi

It does fire:

<head>
</head>
<body onkeydown="(alert(event.keyCode))">
</body>
</html>

--
Best Regards
   Vidar Petursson
http://www.icysoft.com


-

Quote:
> I was trying to come up with a character counter for an input area and
> it worked fine EXCEPT for backspacing --- I couldn't locate the proper
> value for backspace -- do you know it this key actually fires
> keyup/down or keypress?



> > Thanks Peter,
> > This makes perfect sense.  I will adjust my code accordingly!  I was
> > unable to find this clarification in any of the many books I have or
> > the tons of websites I have visited.

> > BTW, I visited your website
> > http://www.netspace.net.au/~torrboy/code/jscriptfaq/ per the URL at
> > the bottom of your response  and got some lightbulbs turned on.  For
> > example, you did a great job of separating JScript, JavaScript, DOM,
> > etc.  Thanks for that, too.  (I highly recommend it.)

> > Rich

> > On Sun, 6 Jun 1999 17:34:31 +1000, "Peter J. Torr"



> > >>I have discovered that the keyCodes for the keydown or keyup events
> do
> > >>not necessarily match the keyCode for the keypress event.

> > >Hi Rich,

> > >This is probably because onKeyUp and onKeyDown give you the hardware
> scan
> > >code for the key, whilst onKeyPress gives you the Unicode number for
> the
> > >character generated by that key. This lets you differentiate between
> keypad
> > >keys and 'normal' keys, for example.

> > >Admittedly, the Internet Explorer DOM documentation doesn't really
> make this
> > >all that clear...

> > >Peter

> > >--

> > >    No longer laying about at home - what a bummer, dude! :-)
> > >JScript FAQ: http://www.netspace.net.au/~torrboy/code/jscriptfaq/

> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.



Tue, 27 Nov 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Reading and transforming keyCodes

2. Help KeyUp toggle event

3. keycodes for Pocket PC

4. Altering the value on keyup event does not trigger change event (IE 5.5)

5. Activex Rich Text Control KeyDown Event

6. msie keydown incompatibility with nnav

7. Browser control, keydown event

8. KeyDown and Beeping

9. Pause Script on KeyDown

10. KeyDown event for VBScript????

11. Keydown

12. Simple Question - Keydown

 

 
Powered by phpBB® Forum Software