Ms word 有没有办法为Microsoft Word加载项创建新的键绑定?

Ms word 有没有办法为Microsoft Word加载项创建新的键绑定?,ms-word,office-js,office-addins,Ms Word,Office Js,Office Addins,我有一个基本的Microsoft Word外接程序,但该应用程序的目标用户是超级用户,他们喜欢使用键盘而不是鼠标进行各种操作 是否有方法将外接程序中的操作/按钮绑定到键或键组合?可以通过键绑定触发操作而不是单击按钮吗 我想附上如下内容: ctrl+l 对这样的事情: function hightlightLongestWord() { Word.run(function (context) { // Queue a command to get

我有一个基本的Microsoft Word外接程序,但该应用程序的目标用户是超级用户,他们喜欢使用键盘而不是鼠标进行各种操作

是否有方法将外接程序中的操作/按钮绑定到键或键组合?可以通过键绑定触发操作而不是单击按钮吗

我想附上如下内容:

ctrl
+
l

对这样的事情:


    function hightlightLongestWord() {
        Word.run(function (context) {
            // Queue a command to get the current selection and then
            // create a proxy range object with the results.
            var range = context.document.getSelection();

            
            // This variable will keep the search results for the longest word.
            var searchResults;
            
            // Queue a command to load the range selection result.
            context.load(range, 'text');
            // Synchronize the document state by executing the queued commands
            // and return a promise to indicate task completion.
            return context.sync()
                .then(function () {
                    $("#template-description").text(range.text);
                    // Get the longest word from the selection.
                    var words = range.text.split(/\s+/);
                    var longestWord = words.reduce(function (word1, word2) { return word1.length > word2.length ? word1 : word2; });

                    // Queue a search command.
                    searchResults = range.search(longestWord, { matchCase: true, matchWholeWord: true });

                    // Queue a commmand to load the font property of the results.
                    context.load(searchResults, 'font');
                })
                .then(context.sync)
                .then(function () {
                    // Queue a command to highlight the search results.
                    searchResults.items[0].font.highlightColor = '#FF0000'; // Green
                    searchResults.items[0].font.bold = true;
                })
                .then(context.sync);
        })
        .catch(errorHandler);
    } 


简短的回答是的。但这不是最实际的。(这是我所知道的在外接程序中执行类似操作的唯一方法)

您可以创建一个javascript事件处理程序来捕获按键组合

以下是一些例子:

这有一个问题,因为外接程序是加载到word的网站,所以您的外接程序需要处于活动状态才能捕获按键。所以,若用户正在向Word写入内容,然后按ctrl+l,那个么若用户并没有首先单击外接程序,则不会发生任何事情

据我所知,覆盖单词自身组合键的唯一方法是通过VBA和宏(请注意,office online不支持宏):


但是,您可以在外接程序中使用一个按钮:当使用ctrl-down=>DoSMTH单击时,当正常单击=>do其他操作时,当单击shift-down=>do超级格式化时。。。等等。

简短回答是。但这不是最实际的。(这是我所知道的在外接程序中执行类似操作的唯一方法)

您可以创建一个javascript事件处理程序来捕获按键组合

以下是一些例子:

这有一个问题,因为外接程序是加载到word的网站,所以您的外接程序需要处于活动状态才能捕获按键。所以,若用户正在向Word写入内容,然后按ctrl+l,那个么若用户并没有首先单击外接程序,则不会发生任何事情

据我所知,覆盖单词自身组合键的唯一方法是通过VBA和宏(请注意,office online不支持宏):

但是,您可以在外接程序中使用一个按钮:当使用ctrl-down=>DoSMTH单击时,当正常单击=>do其他操作时,当单击shift-down=>do超级格式化时。。。等等