I would suggest you to use http://www.autohotkey.com/ .
It would be quite hard to write this as a learners project because you would need to hook your code into the operating system.
So in the spirit of not reinventing the wheel, autohotkey will probably serve your purposes.