Skip to content

Commit

Permalink
Revert "Fix for octalmage#15"
Browse files Browse the repository at this point in the history
This reverts commit c9b3e9b.
  • Loading branch information
Deltatiger committed Jul 25, 2015
1 parent c9b3e9b commit 1d6d5ea
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 56 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
build/
node_modules/
test_scripts/
110 changes: 55 additions & 55 deletions src/robotjs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
using namespace v8;

/*
__ __
| \/ | ___ _ _ ___ ___
__ __
| \/ | ___ _ _ ___ ___
| |\/| |/ _ \| | | / __|/ _ \
| | | | (_) | |_| \__ \ __/
|_| |_|\___/ \__,_|___/\___|
*/

NAN_METHOD(moveMouse)
NAN_METHOD(moveMouse)
{
NanScope();
if (args.Length() < 2)
if (args.Length() < 2)
{
return NanThrowError("Invalid number of arguments.");
return NanThrowError("Invalid number of arguments.");
}
size_t x = args[0]->Int32Value();
size_t y = args[1]->Int32Value();
Expand All @@ -38,12 +38,12 @@ NAN_METHOD(moveMouse)
NanReturnValue(NanNew("1"));
}

NAN_METHOD(moveMouseSmooth)
NAN_METHOD(moveMouseSmooth)
{
NanScope();
if (args.Length() < 2)
if (args.Length() < 2)
{
return NanThrowError("Invalid number of arguments.");
return NanThrowError("Invalid number of arguments.");
}
size_t x = args[0]->Int32Value();
size_t y = args[1]->Int32Value();
Expand All @@ -54,20 +54,20 @@ NAN_METHOD(moveMouseSmooth)
NanReturnValue(NanNew("1"));
}

NAN_METHOD(getMousePos)
NAN_METHOD(getMousePos)
{
NanScope();

MMPoint pos = getMousePos();

//Return object with .x and .y.
Local<Object> obj = NanNew<Object>();
obj->Set(NanNew<String>("x"), NanNew<Integer>((int)pos.x));
obj->Set(NanNew<String>("y"), NanNew<Integer>((int)pos.y));
obj->Set(NanNew<String>("x"), NanNew<Number>(pos.x));
obj->Set(NanNew<String>("y"), NanNew<Number>(pos.y));
NanReturnValue(obj);
}

NAN_METHOD(mouseClick)
NAN_METHOD(mouseClick)
{
NanScope();

Expand All @@ -91,7 +91,7 @@ NAN_METHOD(mouseClick)
}
else
{
return NanThrowError("Invalid mouse button specified.");
return NanThrowError("Invalid mouse button specified.");
}
}
else if (args.Length() > 1)
Expand All @@ -104,7 +104,7 @@ NAN_METHOD(mouseClick)
NanReturnValue(NanNew("1"));
}

NAN_METHOD(mouseToggle)
NAN_METHOD(mouseToggle)
{
NanScope();

Expand All @@ -125,7 +125,7 @@ NAN_METHOD(mouseToggle)
}
else
{
return NanThrowError("Invalid mouse button state specified.");
return NanThrowError("Invalid mouse button state specified.");
}
}

Expand All @@ -147,7 +147,7 @@ NAN_METHOD(mouseToggle)
}
else
{
return NanThrowError("Invalid mouse button specified.");
return NanThrowError("Invalid mouse button specified.");
}
}
else if (args.Length() > 2)
Expand All @@ -161,15 +161,15 @@ NAN_METHOD(mouseToggle)
}

/*
_ __ _ _
_ __ _ _
| |/ /___ _ _| |__ ___ __ _ _ __ __| |
| ' // _ \ | | | '_ \ / _ \ / _` | '__/ _` |
| . \ __/ |_| | |_) | (_) | (_| | | | (_| |
|_|\_\___|\__, |_.__/ \___/ \__,_|_| \__,_|
|___/
|___/
*/

int CheckKeyCodes(char* k, MMKeyCode *key)
int CheckKeyCodes(char* k, MMKeyCode *key)
{
if (!key) return -1;

Expand Down Expand Up @@ -247,7 +247,7 @@ int CheckKeyCodes(char* k, MMKeyCode *key)
}
else if (strlen(k) == 1)
{
*key = keyCodeForChar(*k);
*key = keyCodeForChar(*k);
}
else
{
Expand All @@ -257,42 +257,42 @@ int CheckKeyCodes(char* k, MMKeyCode *key)
return 0;
}

int CheckKeyFlags(char* f, MMKeyFlags* flags)
int CheckKeyFlags(char* f, MMKeyFlags* flags)
{
if (!flags) return -1;

if (strcmp(f, "alt") == 0)
if (strcmp(f, "alt") == 0)
{
*flags = MOD_ALT;
}
else if(strcmp(f, "command") == 0)
else if(strcmp(f, "command") == 0)
{
*flags = MOD_META;
}
else if(strcmp(f, "control") == 0)
else if(strcmp(f, "control") == 0)
{
*flags = MOD_CONTROL;
}
else if(strcmp(f, "shift") == 0)
else if(strcmp(f, "shift") == 0)
{
*flags = MOD_SHIFT;
}
else if(strcmp(f, "none") == 0)
else if(strcmp(f, "none") == 0)
{
*flags = MOD_NONE;
}
else
else
{
return -2;
}

return 0;
}

NAN_METHOD(keyTap)
NAN_METHOD(keyTap)
{
NanScope();

MMKeyFlags flags = MOD_NONE;
MMKeyCode key;

Expand All @@ -304,7 +304,7 @@ NAN_METHOD(keyTap)
k = *kstr;
f = *fstr;

switch (args.Length())
switch (args.Length())
{
case 2:
break;
Expand All @@ -315,26 +315,26 @@ NAN_METHOD(keyTap)
return NanThrowError("Invalid number of arguments.");
}

if (f)
if (f)
{
switch(CheckKeyFlags(f, &flags))
switch(CheckKeyFlags(f, &flags))
{
case -1:
return NanThrowError("Null pointer in key flag.");
break;
case -2:
return NanThrowError("Invalid key flag specified.");
return NanThrowError("Invalid key flag specified.");
break;
}
}

switch(CheckKeyCodes(k, &key))
switch(CheckKeyCodes(k, &key))
{
case -1:
return NanThrowError("Null pointer in key code.");
break;
case -2:
return NanThrowError("Invalid key code specified.");
return NanThrowError("Invalid key code specified.");
break;
default:
tapKeyCode(key, flags);
Expand All @@ -345,13 +345,13 @@ NAN_METHOD(keyTap)
}


NAN_METHOD(keyToggle)
NAN_METHOD(keyToggle)
{
NanScope();

MMKeyFlags flags = MOD_NONE;
MMKeyCode key;

char *k;
bool down;
char *f;
Expand All @@ -362,7 +362,7 @@ NAN_METHOD(keyToggle)
k = *kstr;
f = *fstr;

switch (args.Length())
switch (args.Length())
{
case 3:
break;
Expand All @@ -373,26 +373,26 @@ NAN_METHOD(keyToggle)
return NanThrowError("Invalid number of arguments.");
}

if (f)
if (f)
{
switch(CheckKeyFlags(f, &flags))
switch(CheckKeyFlags(f, &flags))
{
case -1:
return NanThrowError("Null pointer in key flag.");
break;
case -2:
return NanThrowError("Invalid key flag specified.");
return NanThrowError("Invalid key flag specified.");
break;
}
}

switch(CheckKeyCodes(k, &key))
switch(CheckKeyCodes(k, &key))
{
case -1:
return NanThrowError("Null pointer in key code.");
break;
case -2:
return NanThrowError("Invalid key code specified.");
return NanThrowError("Invalid key code specified.");
break;
default:
toggleKeyCode(key, down, flags);
Expand All @@ -402,7 +402,7 @@ NAN_METHOD(keyToggle)
NanReturnValue(NanNew("1"));
}

NAN_METHOD(typeString)
NAN_METHOD(typeString)
{
NanScope();

Expand All @@ -417,15 +417,15 @@ NAN_METHOD(typeString)
}

/*
____
/ ___| ___ _ __ ___ ___ _ __
\___ \ / __| '__/ _ \/ _ \ '_ \
____
/ ___| ___ _ __ ___ ___ _ __
\___ \ / __| '__/ _ \/ _ \ '_ \
___) | (__| | | __/ __/ | | |
|____/ \___|_| \___|\___|_| |_|
*/

NAN_METHOD(getPixelColor)
NAN_METHOD(getPixelColor)
{
NanScope();

Expand All @@ -438,22 +438,22 @@ NAN_METHOD(getPixelColor)
bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, 1, 1));

color = MMRGBHexAtPoint(bitmap, 0, 0);

char hex [7];

//Length needs to be 7 because snprintf includes a terminating null.
//Use %06x to pad hex value with leading 0s.
//Use %06x to pad hex value with leading 0s.
snprintf(hex, 7, "%06x", color);

destroyMMBitmap(bitmap);

NanReturnValue(NanNew(hex));
}

NAN_METHOD(getScreenSize)
NAN_METHOD(getScreenSize)
{
NanScope();

//Get display size.
MMSize displaySize = getMainDisplaySize();

Expand All @@ -466,7 +466,7 @@ NAN_METHOD(getScreenSize)
NanReturnValue(obj);
}

void init(Handle<Object> target)
void init(Handle<Object> target)
{

target->Set(NanNew<String>("moveMouse"),
Expand All @@ -486,7 +486,7 @@ void init(Handle<Object> target)

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

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

Expand Down

0 comments on commit 1d6d5ea

Please # to comment.