What have you tried? I think the only method that would work on an unfocused window is the faking of WM_KEYDOWN and WM_KEYUP, but in Windows the de-facto method for automating another program is using UI Automation. If this is for another OS I just don't know what options you may have.
This is strictly windows only. I have only tried WM_CHAR and WM_KEYDOWN & WM_KEYUP but none of my methods seem to produce any kind of result whatsoever.
Google up UI Automation if the function that you want to trigger with F12 is accessible via a user interface element. Or see if there is a UI pattern for sending keys. Maybe there's one (don't remember right now).