specific key press event

B

birarai

How do i get the 'keypress' event to capture only the 'enter' key
event? The 'keypress' event captures all key press events.

input.addEventListener('keypress', sendButtonPressed, true);

Thanks

birarai
 
O

one man army

birarai said:
How do i get the 'keypress' event to capture only the 'enter' key
event? The 'keypress' event captures all key press events.

input.addEventListener('keypress', sendButtonPressed, true);

I'd guess that the technique is to act on the keypress you are
interested in, and leave the others alone, that way they can cascade
when added in different objects. In DOM/Javascript this seems to be with
a return value of true or false.
 
G

Gérard Talbot

birarai wrote :
How do i get the 'keypress' event to capture only the 'enter' key
event? The 'keypress' event captures all key press events.

Not all. Only non-printable characters.
input.addEventListener('keypress', sendButtonPressed, true);

Thanks

birarai

You can find all the info you need with (studying/examining) these 2
webpages:

http://www.din.or.jp/~hagi3/JavaScript/JSTips/Mozilla/Samples/KeyEvent.htm

http://www.w3.org/2002/09/tests/keys.html

Hint: Query the keyCode if equal to 13 on a keypress.
If you are trying to cancel a form submission, then there are much
better ways to do this.

Gérard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,259
Messages
2,571,035
Members
48,768
Latest member
first4landlord

Latest Threads

Top