views:

38

answers:

2

I'm trying to implement a JavaScript component that captures key-inputs and creates a command prompt interface for the web, I don't want to use text-fields

It's easy to capture input from keys as follows:

$('*').bind( 'keypress', keypressCaptureFunction )

but the bubbling of events is giving me multiple events per key-press, also, using '*' is a bit of a cheat because I don't know what to call bind() on...

How do I properly catch a keypress event?

+2  A: 

$(document).bind('keypress', keypressCaptureFunction);

David Morton
+1  A: 

Try:

$(document).bind( 'keypress', keypressCaptureFunction );

This will listen for the bubble up at the document level and bind one event handler instead of many.

Nick Craver