Word OnKeyDown - detect Navigation pane?

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

Word OnKeyDown - detect Navigation pane?
 
Nicolas Bourgogne




Posts: 5
Joined: 2013-07-22
Good afternoon,

As a follow up to this discussion: http://www.add-in-express.com/forum/read.php?FID=5&TID=12006

I would like to detect when the key down event is triggered from the Navigation pane or search pane.
I cannot find anywhere a property that would indicate that the "active" selection is really the search box rather than the document itself. The reason being that I only want to handle the key stroke if the user is currently working in the document, not typing in the search box.

Thank you,

Nicolas
Posted 24 Jan, 2014 11:25:45 Top
Heinz-Josef Bomanns




Posts: 201
Joined: 2008-02-28
Hi Nicolas,

you may try to use adxWordEvents to update a gobal flag like 'Public IsInWindow As Boolean' in 'WindowActivate' (=True) and 'WindowDeactivate' (=False) and check that flag in your code:

If IsInWindow Then
'DoSomeThing
Else
'Ignore
End If
__________________
Greetings, HJB
Posted 27 Jan, 2014 00:34:23 Top
Nicolas Bourgogne




Posts: 5
Joined: 2013-07-22
Thanks Heinz,

Unfortunately, this doesn't work. The navigation pane is part of the window, so the WindowDeactivate event is not triggered by toggling its display status or typing in it. At least not on Office 2010 64-bit.

Nicolas
Posted 27 Jan, 2014 08:26:11 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Nicolas,

First, you need to use Spy++ to retrieve the class names and captions of the windows in the window chain in which the task pane window resides. Obviously, the details of the window chain may differ for different Word versions. The edit control adds one more window to the chain: when you click what the Search "control" (it is just drawn on the pane), Word creates a RichEdit which handles the user input; when you move the focus off the pane, the RichEdit control is killed.

In the OnKeyDown event, you retrieve the hwnd of the focused window by calling the GetFocus Win API function. Then you use the GetClassName and GetWindowText (plus GetWindowTextLength) Win API functions to retrieve the class name and caption of this window. Finally, you use GetParent to retrieve the parent window of the current window. In this way you can walk up the window chain to find the window the class name and/or title of which you know from studying the Spy++ output. You find the declarations of the above mentioned WinAPI functions at pinvoke.net.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 28 Jan, 2014 05:00:17 Top
Nicolas Bourgogne




Posts: 5
Joined: 2013-07-22
Thanks Andrei!

I was hoping to do it via the application interface itself, but this works perfectly.

Nicolas
Posted 29 Jan, 2014 10:28:35 Top