keystroke recorder

Can I build a keystroke recorder in Applescript?

Probably, but there are several available: http://braden.machacking.net/, http://www.spectorsoft.com/products/Spector_Macintosh/index.html, http://www.burning-bytes.com/monitorerxpro.html

You might also like to check out the discussion under Key Strokes.