A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
Hi priyanka,
Thank you for your response.
To answer your question, you can absolutely make it work the way you described. The quickkeys.json plus functions.ts approach is the correct and fully supported method, so the issue is most likely how the pieces are connected rather than your overall idea.
First, an important clarification about the snippet I shared earlier. The keydown listener code should not be placed in functions.ts, which is why it did not work for you. That file is your command entry point in the runtime, not a focused page listening for keystrokes, so a listener there will never fire. Please remove it, since the sample based approach you are following does not use it at all.
The way this is meant to work is that your quickkeys.json defines each action and the key that triggers it, and your functions.ts then connects that same action to your real function using Office.actions.associate. You do not paste your logic loose into the file. Instead, you pass associate a function that holds the logic to run when the shortcut is pressed:
Office.actions.associate("ChangeColor", function () {
// your logic goes here
return;
});
The first argument, "ChangeColor", must match the action id defined in your quickkeys.json. The second argument is the function that runs when that shortcut fires, and that function is where your actual logic lives.
Since you already have your feature implementations written for your ribbon buttons, you do not need to duplicate that code. You can simply call your existing function from inside the associated function, so the shortcut and the ribbon button both run the same underlying logic:
Office.actions.associate("ChangeColor", function () {
return myExistingFunction();
});
So the chain is that a key press makes Office look up the key in quickkeys.json, find the matching action id, and then run the function you associated with that id.
I hope this clarifies your question. Should you have any further questions, please feel free to reach out and let me know. I'll be happy to help.
If you found this helpful, please kindly upvote it so that other users in this forum can also benefit from this.
Thank you for your time and patience. Wishing you a great day ahead.