Skip to content

Commit

Permalink
Added mouseToggle, closes #8.
Browse files Browse the repository at this point in the history
  • Loading branch information
octalmage committed Feb 4, 2015
1 parent b11648a commit 3f4918b
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/robotjs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,62 @@ NAN_METHOD(mouseClick)
NanReturnValue(NanNew("1"));
}

NAN_METHOD(mouseToggle)
{
NanScope();

MMMouseButton button = LEFT_BUTTON;
bool down;

if (args.Length() > 0)
{
char *d = (*v8::String::Utf8Value(args[0]->ToString()));

if (strcmp(d, "down") == 0)
{
down = true;;
}
else if (strcmp(d, "up") == 0)
{
down = false;
}
else
{
return NanThrowError("Invalid mouse button state specified.");
}
}

if (args.Length() == 2)
{
char *but = (*v8::String::Utf8Value(args[1]->ToString()));

if (strcmp(but, "left") == 0)
{
button = LEFT_BUTTON;
}
else if (strcmp(but, "right") == 0)
{
button = RIGHT_BUTTON;
}
else if (strcmp(but, "middle") == 0)
{
button = CENTER_BUTTON;
}
else
{
return NanThrowError("Invalid mouse button specified.");
}
}
else if (args.Length() > 2)
{
return NanThrowError("Invalid number of arguments.");
}

toggleMouse(down, button);

NanReturnValue(NanNew("1"));
}

/*
_ __ _ _
| |/ /___ _ _| |__ ___ __ _ _ __ __| |
Expand Down Expand Up @@ -187,6 +243,9 @@ void init(Handle<Object> target)
target->Set(NanNew<String>("mouseClick"),
NanNew<FunctionTemplate>(mouseClick)->GetFunction());

target->Set(NanNew<String>("mouseToggle"),
NanNew<FunctionTemplate>(mouseToggle)->GetFunction());

target->Set(NanNew<String>("keyTap"),
NanNew<FunctionTemplate>(keyTap)->GetFunction());

Expand Down

0 comments on commit 3f4918b

Please sign in to comment.