Keystroke logger

I wanted to look at writing a key logger type
application. i.e. a tool that can detect and record
key stroke and mouse movements.
Does anyone have any clues or suggestions on how I can
do this.

thanks