0

I'm working on a custom shortcut but I'm facing the problem, that the key events do not fire when outlook 2013 is focused (with 2007 & 2010 it's working fine). So far, I've tried different solutions. This one seems to be the best so far, the following code is a global hook.

[DllImport("user32.dll")]
static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc callback, IntPtr hInstance, uint threadId);

[DllImport("user32.dll")]
static extern bool UnhookWindowsHookEx(IntPtr hInstance);

[DllImport("user32.dll")]
static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, int wParam, IntPtr lParam);

[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string lpFileName);

private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);

const int WH_KEYBOARD_LL = 13;
const int WM_KEYDOWN = 0x100;

private LowLevelKeyboardProc _proc = hookProc;

private static IntPtr hhook = IntPtr.Zero;

public void SetHook()
{

  IntPtr hInstance = LoadLibrary("User32");
  hhook = SetWindowsHookEx(WH_KEYBOARD_LL, _proc, hInstance, 0);
}

public static IntPtr hookProc(int code, IntPtr wParam, IntPtr lParam)
{
  Debug.WriteLine("key event triggered");
  //...
  return CallNextHookEx(hhook, code, (int)wParam, lParam);
}
md0w
  • 1
  • I've also tried this http://www.codeproject.com/Articles/19004/A-Simple-C-Global-Low => still the same problem when outlook 2013 is focused - the keydown is not firing. – md0w Jul 27 '15 at 12:26
  • 1
    See if this helps, http://stackoverflow.com/questions/2635463/i-have-a-vsto-application-as-an-add-in-to-ms-word-and-i-want-to-set-keyboard-sho/9840871#9840871 – Kiru Jul 28 '15 at 09:33
  • @Kiru: thank you that was the solution :) – md0w Jul 28 '15 at 15:42
  • glad it helped, please upvote if that helped – Kiru Jul 29 '15 at 08:44

0 Answers0