How can I prevent RegisterHotKey from stopping the default action?

advertisements

I'm using the Window's API RegisterHotKey function to run a macro when the F2 key is pressed while a specific application is open and focused.

The problem is, this is stopping the F2 key from working for other applications, such as Excel.

How can I prevent RegisterHotKey from stopping the default action?

I have a system tray application that uses the HotKeyManager class from this answer to register hotkeys. When a specific key is pressed (for example, F2), I use the Windows API to check if a closed-source application is open and focused, and if so send it a series of SendKeys.


From what I understand, you want your global hotkey to work only when one or more selected apps are focused. Can't you simply SendKeys the intercepted strokes if you determine that an incompatible app is in the foreground?

For example,

if (IsSpecificWindowFocused())
{
    // Do work
}
else
{
    // Resend the key to whatever window is current
    SendKeys.Send("{F2}");
}