Bome's Midi Translator Pro is the popular MIDI and keystroke translator: use it for controlling arbitrary software by way of MIDI and keystrokes. Its rich feature set allows it to be used for general Windows automation, too.
It works by specifying mappings for different input and output types. Below is a list of different trigger types (Incoming) and action types (Outgoing). You can combine them as you wish, e.g. do keystroke-to-MIDI conversion, or MIDI-to-mouse mapping.