End Session when the user is inactive (not typing)

Currently my site uses dual session checking one in the server side (about 30 minutes) and the other on the client side (10 minutes). Once the timer ends and the page hasn’t been refreshed the client side checking will end the current session. This is good if the user is just viewing but the problem occurs if the current page has forms that could take more than 10 minutes. My forms and fields are all dynamic and my javascript for this session checking is found on one template found on all pages.

Is there a way to do this:
detect if the user is typing? if yes do/stop the timer else reset the timer and start detecting again

I would listen for both key and mouse events to decide whether the user is there. For example, keydown and mousemove.