Monitoring Mouse and Keyboard Usage

I am looking for an application to monitor keyboard and mouse usage on Ubuntu.

Keyboard usage could be defined as the difference between the first key press and the last key press. The last key press is when a key is pushed followed by a period of inactivity (e.g. 1 minute of non-usage). Total keyboard usage is therefore the sum of each duration of keyboard usage.

Mouse usage is similarly defined to keyboard usage. It is the difference between the first click and the last click, where the last click is a click followed by a period of inactivity. Total mouse usage is the sum of each duration of mouse usage.

Is there a package that has a similar ability to monitor keyboard and mouse usage?