How can I use ffi in NodeJS?

I am creating a Windows robot. To move the mouse this is my code:

var ffi = require('ffi'),
    user32 = ffi.Library('user32', {
        'SetCursorPos': ['long', ['long', 'long']]
    });;


user32.SetCursorPos(100,100);

      

I need a function that using ffi (or any other way) clicks on the given coordinates, for example

click(100,100);

      

+3


source to share


1 answer


This did the trick for me:



var ffi = require('ffi'),
    user32 = ffi.Library('user32', {
        'SetCursorPos': ['long', ['long', 'long']],
        'mouse_event': ['void', ['int', 'int', 'int', 'int', 'int']]
    });;

MOUSEEVENTF_LEFTDOWN = 2;
MOUSEEVENTF_LEFTUP = 4;

user32.SetCursorPos(3, 3);

user32.mouse_event(MOUSEEVENTF_LEFTDOWN, 0 ,0 ,0 ,0);
user32.mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

      

+3


source







All Articles