Skip to content

Commit

Permalink
feat: implement mouse move binding
Browse files Browse the repository at this point in the history
  • Loading branch information
developer239 committed Apr 27, 2023
1 parent d1a4a32 commit 6495642
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cpp/externals/robot-cpp
Submodule robot-cpp updated 2 files
+14 −1 CMakeLists.txt
+1 −3 README.md
22 changes: 21 additions & 1 deletion cpp/src/main.cpp
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);
18 changes: 10 additions & 8 deletions index.js
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,
}

0 comments on commit 6495642

Please sign in to comment.