Skip to content

Commit

Permalink
Got some basic mouse functions working.
Browse files Browse the repository at this point in the history
  • Loading branch information
octalmage committed Aug 31, 2014
1 parent 38c1700 commit d84e253
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 1,158 deletions.
45 changes: 45 additions & 0 deletions autonode.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <node.h>
#include <v8.h>
#include "mouse.h"
#include "deadbeef_rand.h"
#include "screen.h"

using namespace v8;

Handle<Value> moveMouse(const Arguments& args)
{
HandleScope scope;
if (args.Length() < 2)
{
ThrowException(Exception::TypeError(String::New("Wrong number of arguments")));
return scope.Close(Undefined());
}
size_t x = args[0]->Int32Value();
size_t y = args[1]->Int32Value();

MMPoint point;
point = MMPointMake(x, y);
moveMouse(point);
return scope.Close(String::New("1"));
}

Handle<Value> getMousePos(const Arguments& args)
{
HandleScope scope;

MMPoint pos = getMousePos();
Local<Object> obj = Object::New();
obj->Set(String::NewSymbol("x"), Number::New(pos.x));
obj->Set(String::NewSymbol("y"), Number::New(pos.y));
return scope.Close(obj);
}

void init(Handle<Object> target)
{
target->Set(String::NewSymbol("moveMouse"),
FunctionTemplate::New(moveMouse)->GetFunction());

target->Set(String::NewSymbol("getMousePos"),
FunctionTemplate::New(getMousePos)->GetFunction());
}
NODE_MODULE(autonode, init)
4 changes: 2 additions & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
]
],
"sources": ["hello.cc", "deadbeef_rand.c", "mouse.c", "screen.c"]
"sources": ["autonode.cc", "deadbeef_rand.c", "mouse.c", "screen.c"]
}
]
}
}
Loading

0 comments on commit d84e253

Please sign in to comment.