Nw.js: Electron's contents.sendInputEvent equivalent

Created on 4 May 2017  路  10Comments  路  Source: nwjs/nw.js

NW: v0.22.1-sdk
OS: WIN 7 SP1 64

I'm currently on scriptable browser project based on NW which is similar to NightmareJS for Electron.
One of my issue is using input event to automate keyboard/mouse event.
It's easy thing to do in Electron since there is a specific API available for this
https://electron.atom.io/docs/api/web-contents/#contentssendinputeventevent
So the input event is triggered natively
Offcourse it can be done by preloading a javascript that emulate this behavior, but it would be great if NW has this feature too.

Thanks.

feature-request

Most helpful comment

Will add this feature. Thanks.

All 10 comments

Will add this feature. Thanks.

@rogerwang i am kinda need this feature so much.
I have a little C/C++ basics, can you or anyone please help pointing me out where to start ?
so i can implement this myself or maybe do a PR.

Thanks

Hi, are there any alternatives or workarounds to do this? I really need this feature 馃槥

As far as I see this can be done with chrome.debugger API. See a sample here: https://stackoverflow.com/a/46634681/180197

Using chrome.debugger didn't help.

Here's what I tried:

   chrome.debugger.getTargets(function (targets) {
        targets.forEach(function (target, i) {
            if (target.type === 'app' || target.type === 'webview') {
                var debugee = { targetId: target.id }
                chrome.debugger.attach(debugee, '1.2', function () {
                    chrome.debugger.sendCommand(debugee, 'Input.dispatchKeyEvent', {
                        'type': 'keyDown',
                        'key': 'a',
                        'code': 'a',
                        'keyCode': 'a',
                        // 'nativeVirtualKeyCode': null,
                        // 'windowsVirtualKeyCode': null
                    }, function () {
                        chrome.debugger.sendCommand(debugee, 'Input.dispatchKeyEvent', {
                            'type': 'keyUp',
                            'key': 'a',
                            'code': 'a',
                            'keyCode': 'a',
                            // 'nativeVirtualKeyCode': null,
                            // 'windowsVirtualKeyCode': null
                        }, function () {
                            chrome.debugger.detach(debugee)
                        })
                    })
                })
            }
        })
    })

Focused input element (in webview) still doesn't recieve any keyboard keys.

@Christywl please verify with the sample. It could be a bug.

Using above codes, I add a input/webview tag in index.html with nwjs-sdk-v0.29.3, don't see the keyboard keys operations.

@Christywl could you please upload the sample you are using?

Please download 5898.zip. I'm not sure if my sample is correct for this feature.

How about triggering the key event when focusing on input or clicking a button and waiting 2 seconds etc. So the input is focused?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

azer picture azer  路  3Comments

niutech picture niutech  路  4Comments

loretoparisi picture loretoparisi  路  3Comments

gengshenghong picture gengshenghong  路  3Comments

chino23 picture chino23  路  3Comments