Created
September 30, 2014 11:49
-
-
Save LogIN-/42ee42b8c52ea996f571 to your computer and use it in GitHub Desktop.
Node native module control mouse position coordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <node.h> | |
#include <v8.h> | |
#include <stdio.h> | |
#include <X11/X.h> | |
#include <X11/Xlib.h> | |
#include <X11/Xutil.h> | |
using namespace node; | |
using namespace v8; | |
Handle<Value> setXY(const Arguments& args) { | |
HandleScope scope; | |
if (args.Length() != 2) { | |
ThrowException(Exception::TypeError(String::New("This function accepts two argument!"))); | |
return scope.Close(Undefined()); | |
} | |
if (!args[0]->IsNumber() || !args[1]->IsNumber()) { | |
ThrowException(Exception::TypeError(String::New("Input must be a number!"))); | |
return scope.Close(Undefined()); | |
} | |
//Get system window | |
Display *display; | |
Window root_window; | |
// Open Display | |
display = XOpenDisplay(NULL); | |
root_window = XRootWindow(display, 0); | |
XSelectInput(display, root_window, KeyReleaseMask); | |
XWarpPointer(display, None, root_window, 0, 0, 0, 0, args[0]->NumberValue(), args[1]->NumberValue()); | |
XFlush(display); | |
// Close Display | |
XCloseDisplay(display); | |
return scope.Close(Undefined()); | |
} | |
void init(Handle<Object> target) { | |
target->Set(String::NewSymbol("setXY"), | |
FunctionTemplate::New(setXY)->GetFunction()); | |
} | |
NODE_MODULE(mouse, init) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add "-lX11" to binding.gyp libraries:
simple usage (to draw circle with cursor on screen):