.NET 2.0

Counting Mouse Clicks With Clickr

Wednesday, May 09, 2007

 I recently found myself wondering how many times a day I click the mouse. A quick Google turned up a few promising tools, but none of them were really what I had in mind. As a big fan of keyboard shortcuts, I wanted to know not only how many times I click the mouse but also how many times I click the mouse per application, the idea being that I could use this to figure out which application's shortcuts might be worth learning. With this in mind, I present Clickr. Here's what it does:

  • Counts the total number of left, right and middle (wheel) mouse clicks.
  • For each click logs either the description of the executable (default) or window title of the current foreground window. (Logging the description makes the most sense I think. Run two instances of Clickr and log both if you like.)
  • Displays the total clicks, clicks per window and the date and time logging began on a Windows Form.
  • Minimizes to the notification area (system tray).

Clickr Screenshot Most of this was put together using standard .NET 2.0 Windows Forms stuff. The key to making it work was the fact that you can use .NET to set a low level hook to monitor mouse events, and from there it only takes a little more Win32 work to get a handle to the foreground window and ultimately the window title or executable description. Once I had this working, I added a couple of optimizations to firstly cache the descriptions (which are too expensive to fetch for every click) and secondly ensure that I'm not trying to update the form when it's minimized, as this is also fairly expensive and clearly not very sensible.

I'm not sure anyone else will find this particularly useful but I had fun putting it together and so I thought I'd share it here. There's a link to the executable at the bottom of this post, and although it's not exactly production quality I'll put the source code up as well. It should run on Vista and XP (with the .NET 2.0 Framework) but I've not tested it beyond running it on my machine for a few days, so you mileage may very well vary.

Clickr_1_0.zip
Clickr_Source_1_0.zip

3 Comments | .NET 2.0