SetWindowsHookEx C# trap key combinations

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Can't seem to find any sensible C# examples of this, struggling to work out
the correct way to trap key combinations using SetWindowsHookEx with
WH_KEYBOARD_LL, such as ALT-ESC.

private int InterpretKey(int nCode, IntPtr wParam, IntPtr lParam)
{

.....

hookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam,
typeof(KeyboardHookStruct));

if (hookStruct.vkCode == VK_MENU &&
(hookStruct.flags & VK_ESCAPE ) == hookStruct.flags)
{
handled = true;
....
}

.....

}
 
Ok figured this out, there's different codes for the flag checks.

if (hookStruct.vkCode == ESCAPE &&
(hookStruct.flags & LLKHF_ALTDOWN) == hookStruct.flags)
 
Back
Top