First of all, if you install an hook of type
WH_KEYBOARD
then you are not enabled to track the keys sent to other application; you should use
WH_KEYBOARD_LL
instead.
See the code snippet below:
HHOOK hHook = NULL;
LRESULT CALLBACK MyLowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HC_ACTION)
{
KBDLLHOOKSTRUCT* pKb = reinterpret_cast<kbdllhookstruct>(lParam);
bool bAltKeyHeldDown = (pKb->flags & LLKHF_ALTDOWN) != 0;
if (bAltKeyHeldDown && pKb->vkCode == VK_F2)
{
}
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, MyLowLevelKeyboardProc, GetModuleHandle(NULL), 0);
</kbdllhookstruct>