user2678018
user2678018

Reputation: 377

Office add-in - on key pressed - installer

I would like to develop an office add-in for Microsoft Word using HTML5/Javascript API and I need your help with the following questions:

  1. Does the Word Javascript API have an event for "on key pressed"? so any time the user is typing in the document I will be able to catch that event on my add-in?

  2. Is it possible to install a Word Add-in directly without using the office store? so I can bundle my add-in into my own installer (for example NSIS installer)

Thanks Shai

Upvotes: 4

Views: 1751

Answers (2)

Wiged Xolba
Wiged Xolba

Reputation: 11

UPDATE 2022

The example of Michael Saunders is still working, but it covers also other keys, making it much more useful; basically the event fires everytime the cursor moves:

  • any letter
  • any number
  • any punctuation or special character
  • backspace
  • spacebar

what is still not handled is any key which doesn't make the cursor move:

  • del
  • shift
  • any dead key (since they only modify the next-coming character)

Tested on Word 365 (Version 2208)

Upvotes: 0

Michael Saunders
Michael Saunders

Reputation: 2668

There's no API for on on-key-pressed event.

The closest option is the DocumentSelectionChanged API event, which fires every time the user's selection changes. In Word, this event fires on some key presses, such as:

  • Any arrow key press
  • Enter
  • Tab
  • Clicking to position the cursor in the document (not a key press)
  • The first key press of any kind (letter, number, etc.) that immediately follows one of the above types of key press.

Here's the sample:

var doc = Office.context.document;
doc.addHandlerAsync(Office.EventType.DocumentSelectionChanged, function(eventArgs){
    // do something when the selection changes
});

-Michael Saunders, program manager for Office add-ins

Upvotes: 6

Related Questions