Intercept Tab Key

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

Intercept Tab Key
Word add-in required to intercept tab key 
Tim Farrelly




Posts: 4
Joined: 2020-08-05
In our Word add-in, we require to intercept the tab key. Then if the active document is a document with certain characteristics (contains a certain document variable) and the selection is in a table, we want to do something particular.
For all other conditions, including when Word focus is in a dialog or a task pane, we want Word to do its normal thing with the tab (insert a tab in the document or tab to the next field in a dialog, etc).
Is this possible please?
I am familiar with and use the ADXKeyboardShortcut control but I have not been able to determine how to pass on the tab to Word when the conditions are not met for the particular thing we want to do.
Thanks
Tim
Posted 05 Aug, 2020 03:46:59 Top
Andrei Smolin


Add-in Express team


Posts: 17306
Joined: 2006-05-11
Hello Tim,

ADXKeyboardShortcut doesn't let you achieve this as it invariably cancels the key combination specified.

The newest version of the Add-in Express manual includes this section:

Intercepting pressing a key

You may want to use the OnKeyDown event of the add-in module. The ADXKeyDownEventArgs object the event handler supplies allows you to learn the keyboard event details.

To cancel the keyboard event, set the ADXKeyDownEventArgs.Handled property to true and the event won't be passed to other programs such as other add-ins and Office itself. Still, Office may intercept a keyboard event before your add-in receives it and it may even prevent the add-in from receiving the keyboard event. Typically, this occurs with Excel. If the keyboard action changes the workbook, you can work around this limitation by undoing the action; find an example on our forum (https://www.add-in-express.com/forum/read.php?FID=5&TID=12534).

You must not use the object model in this event. This is because the object model isn't ready to process incoming calls in this moment. Use the machinery we describe in Wait a little (https://www.add-in-express.com/docs/net-office-tips.php#wait-a-little) to create a small delay: when the delay is over, the object model is ready. The ADXKeyboardShortcut component described above doesn't impose this restriction.


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 05 Aug, 2020 03:56:17 Top
Tim Farrelly




Posts: 4
Joined: 2020-08-05
Hello Andrei,

Thank you for the quick reply.

The OnKeyDown event does not intercept the Tab key. I type "a", the event fires, I type Tab, the event does not fire. Interestingly, I type Shift-Tab or Ctrl-Tab, the event fires.

Is this a bug?

Thanks
Tim
Posted 05 Aug, 2020 20:02:25 Top
Andrei Smolin


Add-in Express team


Posts: 17306
Joined: 2006-05-11
Hello Tim,

No, this isn't a bug: the corresponding code doesn't contain any 'if' operator. I suppose Word doesn't let the add-in receive the corresponding event.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 06 Aug, 2020 03:59:55 Top