I have written a rough, self-tracking-focused keylogger as part of the Telepath project that Yoni and I were working on: http://www.nickwinter.net/telepath
The Telepath experiment is on hold right now, but the keylogging works. It also captures mouse movements, focused application titles, accelerometry, and light levels, and it can take webcam photos if you really want that (although I’d have to enable it for you). My version also really beeps at me when I type bad-writing adverbs and plays the drums whenever the accelerometer notices sharp motion, which I find hilarious, but which is not inflicted on other users. All the log files are stored locally and it doesn’t do any networking. (It does use a small-but-noticeable amount of CPU because I wanted the timing to be extra precise.)
The caveat is that the log files it generates are full of precise timing information, so that it’s not easy to read them–they’re pretty raw and designed for some scripts to process and do machine learning on, so they look like this:
[1371227112.077378,"keyDown","l",0.03542938,0.003984064]
[1371227112.082514,"keyDown","e",0.03406112,0.005634338]
[1371227112.08862,"keyDown","a",0.03687565,0.003984064]
[1371227112.122852,"keyUp","l",0.04016225,0.02455942]
[1371227112.145655,"keyDown","r",0.01596336,0.03212055]
[1371227112.193424,"keyUp","e",0.02787325,0.003984094]
[1371227112.223676,"keyDown","n",0.05326014,0.04559968]
[1371227112.243925,"keyUp","a",0.03826929,0.0207018]
[1371227112.276419,"keyUp","r",0.03406105,0.003984064]
[1371227112.314229,"keyDown","i",0.03542928,0.01992032]
[1371227112.32228,"keyUp","n",0.01780682,0.02182162]
[1371227112.436801,"keyDown","n",0.03224521,0.006900584]
[1371227112.50824,"keyDown","g",0.03856694,0.01736614]
[1371227112.516851,"keyUp","i",0.04094877,0.003984064]
[1371227112.57439,"keyDown","<space>",0.03020957,0.01690295]
Anyway, if you want, you can download the Telepath app from my website and look at the logs it makes in ~/Library/Application Support/Telepath. It’s only 610 lines of Objective-C, and the keylogging is less than 100 lines of that. Keylogging itself is very easy. Formatting the logs to do what you want is not hard, but everyone wants something different, so you might not find what you want, especially because most people still think keylogging=spyware. If you want to write your own program to do this, I’d be happy to suggest how to do it with some sample code, except I’m going to go get married and run around China for a month, so I’ll be out of touch until mid-July.