-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1a4a32
commit 6495642
Showing
3 changed files
with
32 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,27 @@ | ||
#include <napi.h> | ||
#include "Mouse.h" | ||
|
||
Napi::Value Move(const Napi::CallbackInfo& info) { | ||
Napi::Env env = info.Env(); | ||
|
||
if (info.Length() != 1 || !info[0].IsObject()) { | ||
Napi::TypeError::New(env, "Expected an object with x and y properties").ThrowAsJavaScriptException(); | ||
return env.Null(); | ||
} | ||
|
||
Napi::Object point = info[0].As<Napi::Object>(); | ||
int x = point.Get("x").As<Napi::Number>().Int32Value(); | ||
int y = point.Get("y").As<Napi::Number>().Int32Value(); | ||
|
||
Robot::Mouse::Move({x, y}); | ||
|
||
return env.Null(); | ||
} | ||
|
||
Napi::Object InitAll(Napi::Env env, Napi::Object exports) { | ||
exports.Set("move", Napi::Function::New(env, Move)); | ||
// Add other Mouse methods here | ||
return exports; | ||
} | ||
|
||
NODE_API_MODULE(macoskeyboardmouse, InitAll); | ||
NODE_API_MODULE(robotcpp_node_bindings, InitAll); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
// TODO: this can be simplified and bindings dependency is not necessary | ||
const addon = require('bindings')({ | ||
bindings: 'robotcpp_node_bindings', | ||
// TODO: figure out a better way to do this? | ||
try: [['module_root', 'cpp', 'build', 'Release', 'bindings']] | ||
}) | ||
const robotcpp = require('./cpp/build/Release/robotcpp_node_bindings.node'); | ||
|
||
robotcpp.move({x: 100, y: 200}); | ||
|
||
const Mouse = { | ||
move: (point) => { | ||
robotcpp.move(point); | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
Keyboard: addon.Keyboard, | ||
Mouse: addon.Mouse | ||
Mouse, | ||
} |