How to emulate mouse click in electron?


#1

I just found the ‘mouseUp’, ‘mouseDown’, ‘mouseEnter’ and ‘mouseLeave’ event. How can I emulate mouse click? Thanks a lot.


#2

Just figured it out.
Click emulation must involve two steps. Down and up and also with clickCount;

webview.sendInputEvent({type:'mouseDown', x:300, y: 230, button:'left', clickCount: 1});
webview.sendInputEvent({type:'mouseUp', x:300, y: 230, button:'left', clickCount: 1});

This won’t work without clickCount;

And the solo line below won’t work either.

webview.sendInputEvent({type:'mouseUp', x:250, y: 300, button:'left', clickCount: 1, modifiers: ['leftButtonDown']});

#3

What is the webview object you’re using here?


#4

Note that this will not work if the x and y coords aren’t integers.

@sandover See https://electron.atom.io/docs/api/webview-tag/