0

I'm working on the react js Office add-in Projects. I have already been able to create the sidebar and get the Word header, body and footer content using this code.

await Word.run(async (context) => {
    const header = context.document.sections.getFirst().getHeader("Primary").getOoxml();
    const body = context.document.body.getOoxml();
    const footer = context.document.sections.getFirst().getFooter("Primary").getOoxml();
    await context.sync();
    saveDocument({
        fileName: "test file",
        headerXml: header.value.toString(),
        bodyXml: body.value.toString(),
        footerXml: footer.value.toString()
    });
});

And also I want to get the real-time keyboard event. I tried this example:

doc.addHandlerAsync(Office.EventType.DocumentSelectionChanged, function (eventArgs: any) {
    console.log(eventArgs);
});

But I can't figure out the entered key from the object. Here I have attached the image that I get from this console.log:

Console logging

I need a solution to capture the real-time keyboard inputs that enter in the word document from the add-in.

Aaron Meese
  • 1,670
  • 3
  • 22
  • 32
  • I was looking at keyboard shortcut events, which sounds similar to this. I found https://learn.microsoft.com/en-us/office/dev/add-ins/design/keyboard-shortcuts which suggests can only do it for excel. – Bobby Koteski May 29 '23 at 04:05

0 Answers0