Skip to content

Commit

Permalink
fixes keyTap not releasing. allows for multiple keypresses or keytaps…
Browse files Browse the repository at this point in the history
… in a row by adding sleep function. adds missing keys
  • Loading branch information
spatializes committed May 25, 2015
1 parent 527f9d9 commit 47ff4a2
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions src/robotjs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,18 @@ int CheckKeyCodes(char* k, MMKeyCode *key) {
{
*key = K_ALT;
}
else if (strcmp(k, "cmd") == 0)
else if (strcmp(k, "command") == 0)
{
*key = K_META;
}
else if (strcmp(k, "control") == 0)
{
*key = K_CONTROL;
}
else if (strcmp(k, "shift") == 0)
{
*key = K_SHIFT;
}
else if (strcmp(k, "backspace") == 0)
{
*key = K_BACKSPACE;
Expand Down Expand Up @@ -248,18 +256,39 @@ int CheckKeyFlags(char* f, MMKeyFlags* flags) {
if (!flags) return -1;

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

return 0;
}

int mssleep(unsigned long millisecond)
{
struct timespec req;
time_t sec=(int)(millisecond/1000);
millisecond=millisecond-(sec*1000);
req.tv_sec=sec;
req.tv_nsec=millisecond*1000000L;
while(nanosleep(&req,&req)==-1)
continue;
return 1;
}

NAN_METHOD(keyTap)
{
NanScope();
Expand Down Expand Up @@ -308,6 +337,7 @@ NAN_METHOD(keyTap)
break;
default:
tapKeyCode(key, flags);
mssleep(10);
}

NanReturnValue(NanNew("1"));
Expand Down Expand Up @@ -337,8 +367,6 @@ NAN_METHOD(keyToggle)
break;
case 2:
f = NULL;
case 1:
f = NULL;
break;
default:
return NanThrowError("Invalid number of arguments.");
Expand Down Expand Up @@ -366,6 +394,7 @@ NAN_METHOD(keyToggle)
break;
default:
toggleKeyCode(key, down, flags);
mssleep(10);
}

NanReturnValue(NanNew("1"));
Expand Down

0 comments on commit 47ff4a2

Please sign in to comment.