Stephen Wolfram’s “The Personal Analytics of My Life”, made me wonder about things like: How many keystrokes do you type a day? What keys do I use the least/most? Which application do I use the letter ‘z’ the most? Then last year I got my first mechanical keyboard so I figured I had to do something about it.
When I tried to start collecting the data to answer these questions, I realized that I would need a keylogger, sadly there was no keylogger that was both free, open source and provided an easy way to query your keystrokes. After playing around with some of Apple’s APIs, I came up with a very simple and barely usable prototype, today after a year and about 30 days of sporadic development (git log says so), I release Keystats 1.0.0.
Keystats stores all your keystroke data into a SQLite database, so you can query for anything you need, for example:
The top five most used applications in the past 7 days:
sqlite> SELECT bundle_id, count(bundle_id) FROM keystrokes WHERE timestamp >= strftime('%Y-%m-%d 00:00:00', 'now', '-7 day', 'localtime') GROUP BY bundle_id ORDER BY COUNT(bundle_id) DESC LIMIT 5;
com.apple.Terminal|118276
com.wolfram.Mathematica|4182
Now let’s look at an application in specific (for example MacVim) and the count of the three most used keys:
SELECT ascii, COUNT(ascii) FROM keystrokes WHERE bundle_id = 'org.vim.MacVim' GROUP BY ascii ORDER BY COUNT(ascii) DESC LIMIT 3;
These are just two trivial examples that you could have otherwise inferred because: (a) I write software on a daily basis using vim and (b) I make inefficient use of the navigation keys, however this goes to show the kind of things you can do.
The intent is not to make Keystats the ultimate resource to analyze your keystroke data, but instead to provide a flexible source (read database) to answer the questions you have.
For every keystroke you type, the following information is obtained and logged into the keystrokes database:
Current time with the following format 2013-12-27 00:17:40.
Front-most application's bundle identifier (Safari -> com.apple.Safari).
Keystats is hosted on Github.
Keystats is not intended and should not be used as a malicious application, it is the responsibility of the end user to make legal and safe usage of the program.