views:

216

answers:

1

I have a jQuery setInterval function named "timerIncrement" that times out (stops incrementing the variable [licount]) after x-seconds. to resume this interval I have a .mousemove function which looks like this:

$(this).mousemove(function(){ licount = 0; timerIncrement(); });

what I'm looking for is a way to do this exact thing (resume the timerIncrement function) if a keystroke is made.

Can someone please help with this...

+2  A: 
$(this).keypress(function(){ licount = 0; timerIncrement(); });

By the way, if you want the keypress to trigger on the entire document, it may be better to use "document" instead of "this"... perhaps in both situations:

$(document).keypress(function() { licount = 0; timerIncrement(); });

See more here.

David Morton
I was about to post exactly the same thing, character for character.
karim79
is there any way I can link the .mousemove and .keypress together without having to duplicate the code for both functions?like $(document).mousemove or $(document).keypress....?
sadmicrowave
You could do something like:function wakeup() = { licount = 0; timerIncrement(); };$(document).keypress(wakeup).mousemove(wakeup);
David Morton
thanks!!! I know I sound like a jQuery noob right now but everyone's gotta start somewhere...that being said, thanks alot for everyone's help!!
sadmicrowave