none
Need to create a local keyboard hook to bind a keyboard shortcut with Outlook Add-in. RRS feed

  • Question

  • Need to create a local keyboard hook to bind a keyboard shortcut with Outlook. I am creating an outlook VSTO add-in in C#. So far i am able to create global keyboard hook. But the shorcut triggers the event from other applications as well other than Outlook. Is there any way to create a local one instead of a global hook?
    • Edited by Ari_1012 Tuesday, July 9, 2013 1:32 PM
    Tuesday, July 9, 2013 1:27 PM

Answers

All replies

  • Have you looked at http://support.microsoft.com/default.aspx?scid=kb;en-us;318804? As all Outlook object model code as well as all COM addin code runs in the Outlook thread and process space this article should apply to what you want.

    Ken Slovak MVP - Outlook

    Tuesday, July 9, 2013 3:47 PM
  • Thanks Ken...

    I am able to get the current threadId using AppDomain.GetCurrentThreadId() API but hhook is returning 0 instead of a non-zero value

    hhook = SetWindowsHookEx(WH_KEYBOARD_LL, keyHookProc, (IntPtr)0, AppDomain.GetCurrentThreadId()).

    I am using keyboard hook. While in outlook, if user press the shortcut key, then a message (currently selected item) will be saved.

    I am creating reference of the hook class in AddIn class and then in AddIn_Startup, I am adding the Key.

    If I use 0 instead of  AppDomain.GetCurrentThreadId(), then I am getting a non-zero value in hhook.

    Please help.


    • Edited by Ari_1012 Wednesday, July 10, 2013 8:47 AM Want to add more
    Wednesday, July 10, 2013 7:39 AM
  • Thanks Ken...

    I am able to get the current threadId using AppDomain.GetCurrentThreadId() API but hhook is returning 0 instead of a non-zero value

    hhook = SetWindowsHookEx(WH_KEYBOARD_LL, keyHookProc, (IntPtr)0, AppDomain.GetCurrentThreadId()).

    I am using keyboard hook. While in outlook, if user press the shortcut key, then a message (currently selected item) will be saved.

    I am creating reference of the hook class in AddIn class and then in AddIn_Startup, I am adding the Key.

    If I use 0 instead of  AppDomain.GetCurrentThreadId(), then I am getting a non-zero value in hhook.

    Please help.


    I think this has something to do with WH_KEYBOARD_LL. The constant value for WH_KEYBOARD_LL is 13. When I changed to some other value, then i am getting a non-zero value for hhook.

    Can you suggest which constant will work instead of WH_KEYBOARD_LL?

    Wednesday, July 10, 2013 9:07 AM
  • Take a look at http://www.codeproject.com/Articles/19004/A-Simple-C-Global-Low-Level-Keyboard-Hook

    It appears to me that your hInstance value might not be correct.


    Ken Slovak MVP - Outlook

    Wednesday, July 10, 2013 3:06 PM