C# Outlook 2013 PlugIn Keyboard Events using CallNextHookEx RRS feed

  • General discussion

  • Hello, 

    I'm trying to write a simple plugin for Outlook when you press a key (not an exiting shortcut) to do something

    Is working for outlook 2010 but is not working for outlook 2013

    I can see the hook working when Outlook doesn't have the focus , but when the outlook 2013 has the focus nothing happens 

    here is the code

    static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc callback, IntPtr hInstance, uint threadId);
    static extern bool UnhookWindowsHookEx(IntPtr hInstance);
    static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, int wParam, IntPtr lParam);
    static extern IntPtr LoadLibrary(string lpFileName);
    private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
    const int WH_KEYBOARD_LL = 19;
    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);

    Thank you,


    • Edited by MariusNY Wednesday, September 23, 2015 11:49 PM ,
    Wednesday, September 23, 2015 11:47 PM