4

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

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) will click to given coordinates like

click(100,100);

1 Answer 1

4

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.