See this.

I've only used AutoHotKey and AutoIt, and not in great depth. They'd do what you want, but you'd have a learning curve.