I made a program that does something similar to this, but using a mobile device (connected via Telnet) as a remote instead of an IR remote.
My program let you have a profile for each program, and a universal one to fall back upon if one didn't exist for the program you're using. And it would switch to the profile automatically for whatever program was currently in-focus.
Could you do something similar?
That way we could for example, have a different profile for Media Player than we would Powerpoint.