3

I've made a WPF application and I was able to hook some of the windows combinations. ALT+TAB is hooked and it is doing nothing when my application is running (as expected). The problem is when I press the CTRL+ALT+TAB I get the same effect as ALT+TAB. Do you guys have any idea on how to hook this kind of combination?

EDIT:

I have already successfully hooked ALT+TAB. I do want to hook CTRL+ALT+TAB. I've tried this project example to make this happen.

Here's the code that makes the hook:

private static IntPtr KeyboardHookHandler(int nCode, IntPtr wParam, 
                  ref KBHookStruct lParam){
if (nCode == 0)
{
    if (((lParam.vkCode == 0x09) && (lParam.flags == 0x20)) ||  // Alt+Tab
    ((lParam.vkCode == 0x1B) && (lParam.flags == 0x20)) ||      // Alt+Esc
    ((lParam.vkCode == 0x1B) && (lParam.flags == 0x00)) ||      // Ctrl+Esc
    ((lParam.vkCode == 0x5B) && (lParam.flags == 0x01)) ||      // Left Windows Key
    ((lParam.vkCode == 0x5C) && (lParam.flags == 0x01)) ||      // Right Windows Key
    ((lParam.vkCode == 0x73) && (lParam.flags == 0x20)) ||      // Alt+F4
    ((lParam.vkCode == 0x20) && (lParam.flags == 0x20)))        // Alt+Space
    {
        return new IntPtr(1);
    }
}

return CallNextHookEx(hookPtr, nCode, wParam, ref lParam);}
Mwiza
  • 7,780
  • 3
  • 46
  • 42
Ricardo Mota
  • 1,194
  • 2
  • 12
  • 25
  • Sorry I do not get your question. Which one you want to hook "Alt+Tab" or "Ctrl+Alt+Tab"? Have you tried anything? – Nazmul May 19 '15 at 15:03

1 Answers1

0

Answer 1

You can try like below it work for CTRL + SHIFT + TAB and CTRL + TAB

private void HandleKeyDownEvent(object sender, KeyEventArgs e)
{
   if (e.Key == Key.Tab && (Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == (ModifierKeys.Control | ModifierKeys.Shift))
   {
      MessageBox.Show("CTRL + SHIFT + TAB trapped");
   }

   if (e.Key == Key.Tab && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
   {
      MessageBox.Show("CTRL + TAB trapped");
   }
}

Answer 2

should look something like:

((lParam.flags & 33 == 33) && (lParam.flags & 22 == 22))

32 and 22 are arbitrary in this example. You need to figure out what values ALT and CTRL actually are. They will be 1, 2, 4 ... 16, 32 etc. so that they can be OR'ed together into a single value.

Nazmul
  • 575
  • 3
  • 18