keyboard-shortcutsoffice-jsoffice-addinsword-addinsword-web-addins

How to add an event handler for a specific keyboard command?


Is there a way to subscribe or register an event handler to listen for keyboard commands in office add-ins?

My goal is to insert a paragraph when a user uses a specific keyboard command, for example, on ctrl+return, I would like to add a 'Hello world' paragraph to the end of the document.

Note: I am using the JS word add-in template, which makes use of the Office JS API.


Solution

  • The Office JavaScript API (OfficeJS) doesn't provide anything for handling keyboard shortcuts in Office applications except Excel. Keyboard shortcuts are currently only supported on Excel and only on these platforms and builds:

    Read more about that in the Add custom keyboard shortcuts to your Office Add-ins article. Also you may find the Use keyboard shortcuts for Office add-in actions sample code.

    You can post or vote for an existing feature request on Tech Community where they are considered when the Office dev team goes through the planning process.