none
How to detect mouse click or Keyboard input in Word Document? RRS feed

  • Question

  • Hi All,

    In my VSTO addin application, I want to detect mouse click or keyboard input in my word document, and then take different action. I know we can use SelectionEventHandler to handle word selection event, but this cannot detect mouse or keyboard. Could you please let me how to achieve this goal.

    Thanks in advance.

    Ricky

    Wednesday, December 17, 2014 6:10 AM

Answers

  • Hello Ricky,

    The Word object model (nor VSTO) doesn't provide such events. You need to use Windows API functions to detect mouse or keyboard actions.


    Wednesday, December 17, 2014 8:55 AM
  • Hi Richy Yan,

    As far as I know, we can use SetWindowsHookEx function to install an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events.

    You can get more detail about this method from link below:

    SetWindowsHookEx

    Also here is an article describe how to use Windows hook using C#:
    How to set a Windows hook in Visual C# .NET

    If you still have issue using Windows API, I suggest that you get more effective response from General Windows Desktop Development Issues forum.

    In addtion, personally I don't recommend use Windows API to hook event in VSTO solution. It would make the Office prodcut unstable.

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 18, 2014 7:27 AM
    Moderator

All replies

  • Any one know?
    Wednesday, December 17, 2014 8:22 AM
  • Hello Ricky,

    The Word object model (nor VSTO) doesn't provide such events. You need to use Windows API functions to detect mouse or keyboard actions.


    Wednesday, December 17, 2014 8:55 AM
  • Hi Engene,

    Which Windows API functions should I use? I am not familiar with that part. Or is there any sample about that?

    Thanks,

    Wednesday, December 17, 2014 9:30 AM
  • Hi Richy Yan,

    As far as I know, we can use SetWindowsHookEx function to install an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events.

    You can get more detail about this method from link below:

    SetWindowsHookEx

    Also here is an article describe how to use Windows hook using C#:
    How to set a Windows hook in Visual C# .NET

    If you still have issue using Windows API, I suggest that you get more effective response from General Windows Desktop Development Issues forum.

    In addtion, personally I don't recommend use Windows API to hook event in VSTO solution. It would make the Office prodcut unstable.

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 18, 2014 7:27 AM
    Moderator