简体   繁体   English

使用 chrome.debugger 库发送信件的正确语法是什么?

[英]Using the chrome.debugger library what is the proper syntax for sending a letter?

I have been successful in sending aa letter (or text string using this syntax):我已经成功发送了一封信(或使用此语法的文本字符串):

chrome.debugger.sendCommand({ tabId: tabs[0].id },'Input.dispatchKeyEvent',{ type: 'keyDown', text: "b", isKeypad: true });

And this would be fine for most of my needs but I really want to be able to send special characters like tab.这可以满足我的大部分需求,但我真的希望能够发送特殊字符,如制表符。 The first step would be for me to be able to send a character using the parameters like the windowsVirtualKeyCode or nativeVirtualKeyCode but when I replace the line above with something like this I don't get any response.第一步是让我能够使用诸如 windowsVirtualKeyCode 或 nativeVirtualKeyCode 之类的参数发送一个字符,但是当我用类似这样的东西替换上面的行时,我没有得到任何响应。

chrome.debugger.sendCommand({ tabId: tabs[0].id },'Input.dispatchKeyEvent',{ type: 'keyDown', windowsVirtualKeyCode: 66, nativeVirtualKeyCode: 66, isKeypad: true });

I'm not sure why the code at the top works and the bottom does not.我不确定为什么顶部的代码有效而底部的代码无效。 Perhaps I am using the wrong decimal for the letter b.也许我为字母 b 使用了错误的小数点。 Or more likely I am missing a parameter that is needed.或者更有可能我错过了所需的参数。 My ultimate goal after verifying that I can write a windowsVirtualKeyCode: 0x42 successfully will be to then send a tab character which I am thinking will be a decimal value of 9.在验证我可以成功编写 windowsVirtualKeyCode: 0x42 之后,我的最终目标是发送一个制表符,我认为它是十进制值 9。

I can't figure out where my second line is not producing the same response when in place of the top line which is working.我无法弄清楚当我的第二行代替正在工作的顶行时,我的第二行在哪里没有产生相同的响应。

Below function will press Tab key:- function 下面会按 Tab 键:-


function pressTab(tabId) {
    // dispatch rawKeyDown
    chrome.debugger.sendCommand({
        tabId: tabId
    }, 'Input.dispatchKeyEvent', {
        autoRepeat: false,
        code: "Tab",
        isKeypad: false,
        key: "Tab",
        location: 0,
        modifiers: 0,
        text: "",
        type: "rawKeyDown",
        unmodifiedText: "",
        windowsVirtualKeyCode: 9
    })
    
    // dispatch keyUp
    chrome.debugger.sendCommand({
        tabId: tabId
    }, 'Input.dispatchKeyEvent', {
        code: "Tab",
        key: "Tab",
        location: 0,
        modifiers: 0,
        type: "keyUp",
        windowsVirtualKeyCode: 9
    })    
}

pressTab(tabs[0].id)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM