none
Outlook - How To Capture Keypress Event inside Compose Email body(Mail Item)? RRS feed

  • Question

  • I need to capture the keypress event when a user types the contents inside the mail body. When the user presses the spacebar the previous word has to be read from the compose mail body. How can this keypress event be captured within the compose mail window from the mail body??? Any suggestions or any help would be greatly appreciated. 

    Thanks, 
    John Jay 
    Thursday, June 14, 2012 7:25 PM

Answers

All replies

  • In Outlook 2007/2010, use the Inspector.WordEditor property to retrieve the Document Word object.

    You should then be able to use Word events to capture the keyboard input.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Thursday, June 14, 2012 7:33 PM
  • Hi Dmitry,

          Thanks a lot for your reply. I tried using word editor but i cud'nt get the exact function to get the keypress event. I have included my code below.

    Outlook.Application outlookApplication = new Outlook.Application(); 

    Outlook.MailItem mail = (Outlook.MailItem)outlookApplication.ActiveInspector().CurrentItem;

    Outlook.Inspector olInspector = mail.GetInspector;   

    Microsoft.Office.Interop.Word.Document document = (Microsoft.Office.Interop.Word.Document)olInspector.WordEditor;


    from document object how to proceed further??

    Thanks,

    John Jay

     


    Tuesday, June 19, 2012 8:06 PM
  • I am not a Word expert, but I think you are right - the best you can do is get a notification that the document was modified (Application.DocumentChange and Application.WindowSelectionChange)

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Thursday, June 28, 2012 9:47 PM
  • John,

    Do you still need assistance on this question? Since Word object modle doesn't provide exact event for key press, you will need use Win32 API to set such hook:

    http://pinvoke.net/default.aspx/user32/SetWindowsHookEx.html or

    http://support.microsoft.com/default.aspx?scid=kb;en-us;318804#3

    Hope this helps.

    thanks.


    Forrest Guo | MSDN Community Support | Feedback to manager

    Monday, July 9, 2012 5:45 AM
    Moderator