Word application OnKeyDown - handle only when document has focus (not a dialog)?

Add-in Express™ Support Service
That's what is more important than anything else

Word application OnKeyDown - handle only when document has focus (not a dialog)?
 
Nicolas Bourgogne


Guest


Good afternoon,

I have developed ab add-ins for Word in which I capture the "OnKeyDown" event.
Is there a way to only capture those events when the document itself has focus, not a dialog (such as "Find and Replace" for example)? Right now it captures all keys strokes, which causes issues if the user is actually typing in a dialog.

Thank you,

Nicolas
Posted 27 Nov, 2013 12:41:38 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Nicholas,

If you use Word 2013, then you can compare the result of the GetActiveWindow() WinAPI function (see http://pinvoke.net/default.aspx/user32/GetActiveWindow.html) and the Window.Hwnd property of WordApp.ActiveWindow. If you use other Word versions, you'll need to call GetActiveWindow() when the Word window activates and compare this value with the value it returns when in the OnKeyDown event handler.


Andrei Smolin
Add-in Express Team Leader
Posted 28 Nov, 2013 05:09:08 Top
Nicolas Bourgogne


Guest


Thanks Andrei,

I had thought of that but didn't see the WindowActivate event.

Works like a charm :o)

Nicolas
Posted 28 Nov, 2013 09:01:17 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
My pleasure! ))


Andrei Smolin
Add-in Express Team Leader
Posted 29 Nov, 2013 02:56:31 Top