Skip to content

Commit 3f4918b

Browse files
committed
Added mouseToggle, closes #8.
1 parent b11648a commit 3f4918b

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/robotjs.cc

+59
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,62 @@ NAN_METHOD(mouseClick)
102102
NanReturnValue(NanNew("1"));
103103
}
104104

105+
NAN_METHOD(mouseToggle)
106+
{
107+
NanScope();
108+
109+
MMMouseButton button = LEFT_BUTTON;
110+
bool down;
111+
112+
if (args.Length() > 0)
113+
{
114+
char *d = (*v8::String::Utf8Value(args[0]->ToString()));
115+
116+
if (strcmp(d, "down") == 0)
117+
{
118+
down = true;;
119+
}
120+
else if (strcmp(d, "up") == 0)
121+
{
122+
down = false;
123+
}
124+
else
125+
{
126+
return NanThrowError("Invalid mouse button state specified.");
127+
}
128+
}
129+
130+
if (args.Length() == 2)
131+
{
132+
char *but = (*v8::String::Utf8Value(args[1]->ToString()));
133+
134+
if (strcmp(but, "left") == 0)
135+
{
136+
button = LEFT_BUTTON;
137+
}
138+
else if (strcmp(but, "right") == 0)
139+
{
140+
button = RIGHT_BUTTON;
141+
}
142+
else if (strcmp(but, "middle") == 0)
143+
{
144+
button = CENTER_BUTTON;
145+
}
146+
else
147+
{
148+
return NanThrowError("Invalid mouse button specified.");
149+
}
150+
}
151+
else if (args.Length() > 2)
152+
{
153+
return NanThrowError("Invalid number of arguments.");
154+
}
155+
156+
toggleMouse(down, button);
157+
158+
NanReturnValue(NanNew("1"));
159+
}
160+
105161
/*
106162
_ __ _ _
107163
| |/ /___ _ _| |__ ___ __ _ _ __ __| |
@@ -187,6 +243,9 @@ void init(Handle<Object> target)
187243
target->Set(NanNew<String>("mouseClick"),
188244
NanNew<FunctionTemplate>(mouseClick)->GetFunction());
189245

246+
target->Set(NanNew<String>("mouseToggle"),
247+
NanNew<FunctionTemplate>(mouseToggle)->GetFunction());
248+
190249
target->Set(NanNew<String>("keyTap"),
191250
NanNew<FunctionTemplate>(keyTap)->GetFunction());
192251

0 commit comments

Comments
 (0)