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

531 Views Asked by At

I have been successful in sending a a 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.

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. 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.

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.

1

There are 1 best solutions below

0
On

Below function will press Tab key :-


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)