Skip to content

Commit b910e7e

Browse files
committed
add insert-key
1 parent ebc1322 commit b910e7e

File tree

2 files changed

+48
-45
lines changed

2 files changed

+48
-45
lines changed

src/keycode.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "os.h"
66

77
#ifdef __cplusplus
8-
extern "C"
8+
extern "C"
99
{
1010
#endif
1111

@@ -14,7 +14,7 @@ extern "C"
1414
#include <Carbon/Carbon.h> /* Really only need <HIToolbox/Events.h> */
1515
#include <ApplicationServices/ApplicationServices.h>
1616
#import <IOKit/hidsystem/ev_keymap.h>
17-
17+
1818
enum _MMKeyCode {
1919
K_NOT_A_KEY = 9999,
2020
K_BACKSPACE = kVK_Delete,
@@ -48,6 +48,7 @@ enum _MMKeyCode {
4848
K_SHIFT = kVK_Shift,
4949
K_CAPSLOCK = kVK_CapsLock,
5050
K_SPACE = kVK_Space,
51+
K_INSERT = kVK_Insert,
5152
K_PRINTSCREEN = K_NOT_A_KEY,
5253

5354
K_AUDIO_VOLUME_MUTE = 1007,
@@ -170,6 +171,7 @@ enum _MMKeyCode {
170171
K_CAPSLOCK = VK_CAPITAL,
171172
K_SPACE = VK_SPACE,
172173
K_PRINTSCREEN = VK_SNAPSHOT,
174+
K_INSERT = VK_INSERT,
173175

174176
K_AUDIO_VOLUME_MUTE = VK_VOLUME_MUTE,
175177
K_AUDIO_VOLUME_DOWN = VK_VOLUME_DOWN,

src/robotjs.cc

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ int mouseDelay = 10;
1818
int keyboardDelay = 10;
1919

2020
/*
21-
__ __
22-
| \/ | ___ _ _ ___ ___
21+
__ __
22+
| \/ | ___ _ _ ___ ___
2323
| |\/| |/ _ \| | | / __|/ _ \
2424
| | | | (_) | |_| \__ \ __/
2525
|_| |_|\___/ \__,_|___/\___|
@@ -238,21 +238,21 @@ NAN_METHOD(setMouseDelay)
238238
info.GetReturnValue().Set(Nan::New(1));
239239
}
240240

241-
NAN_METHOD(scrollMouse)
241+
NAN_METHOD(scrollMouse)
242242
{
243243
Nan::HandleScope scope;
244244

245245
//Get the values of magnitude and direction from the arguments list.
246-
if(info.Length() == 2)
246+
if(info.Length() == 2)
247247
{
248248
int scrollMagnitude = info[0]->Int32Value();
249249
char *s;
250250

251251
Nan::Utf8String sstr(info[1]);
252252
s = *sstr;
253-
253+
254254
MMMouseWheelDirection scrollDirection;
255-
255+
256256
if (strcmp(s, "up") == 0)
257257
{
258258
scrollDirection = DIRECTION_UP;
@@ -265,26 +265,26 @@ NAN_METHOD(scrollMouse)
265265
{
266266
return Nan::ThrowError("Invalid scroll direction specified.");
267267
}
268-
268+
269269
scrollMouse(scrollMagnitude, scrollDirection);
270270
microsleep(mouseDelay);
271-
271+
272272
info.GetReturnValue().Set(Nan::New(1));
273-
}
274-
else
273+
}
274+
else
275275
{
276276
return Nan::ThrowError("Invalid number of arguments.");
277277
}
278278
}
279279
/*
280-
_ __ _ _
280+
_ __ _ _
281281
| |/ /___ _ _| |__ ___ __ _ _ __ __| |
282282
| ' // _ \ | | | '_ \ / _ \ / _` | '__/ _` |
283283
| . \ __/ |_| | |_) | (_) | (_| | | | (_| |
284284
|_|\_\___|\__, |_.__/ \___/ \__,_|_| \__,_|
285-
|___/
285+
|___/
286286
*/
287-
struct KeyNames
287+
struct KeyNames
288288
{
289289
const char* name;
290290
MMKeyCode key;
@@ -323,7 +323,8 @@ static KeyNames key_names[] =
323323
{ "shift", K_SHIFT },
324324
{ "space", K_SPACE },
325325
{ "printscreen", K_PRINTSCREEN },
326-
326+
{ "insert", K_INSERT },
327+
327328
{ "audio_mute", K_AUDIO_VOLUME_MUTE },
328329
{ "audio_vol_down", K_AUDIO_VOLUME_DOWN },
329330
{ "audio_vol_up", K_AUDIO_VOLUME_UP },
@@ -336,7 +337,7 @@ static KeyNames key_names[] =
336337
{ "audio_forward", K_AUDIO_FORWARD },
337338
{ "audio_repeat", K_AUDIO_REPEAT },
338339
{ "audio_random", K_AUDIO_RANDOM },
339-
340+
340341
{ "lights_mon_up", K_LIGHTS_MON_UP },
341342
{ "lights_mon_down", K_LIGHTS_MON_DOWN },
342343
{ "lights_kbd_toggle",K_LIGHTS_KBD_TOGGLE },
@@ -359,7 +360,7 @@ int CheckKeyCodes(char* k, MMKeyCode *key)
359360
*key = K_NOT_A_KEY;
360361

361362
KeyNames* kn = key_names;
362-
while (kn->name)
363+
while (kn->name)
363364
{
364365
if (strcmp(k, kn->name) == 0)
365366
{
@@ -369,7 +370,7 @@ int CheckKeyCodes(char* k, MMKeyCode *key)
369370
kn++;
370371
}
371372

372-
if (*key == K_NOT_A_KEY)
373+
if (*key == K_NOT_A_KEY)
373374
{
374375
return -2;
375376
}
@@ -577,9 +578,9 @@ NAN_METHOD(typeStringDelayed)
577578
{
578579
char *str;
579580
Nan::Utf8String string(info[0]);
580-
581+
581582
str = *string;
582-
583+
583584
size_t cpm = info[1]->Int32Value();
584585

585586
typeStringDelayed(str, cpm);
@@ -600,12 +601,12 @@ NAN_METHOD(setKeyboardDelay)
600601
}
601602

602603
/*
603-
____
604-
/ ___| ___ _ __ ___ ___ _ __
605-
\___ \ / __| '__/ _ \/ _ \ '_ \
604+
____
605+
/ ___| ___ _ __ ___ ___ _ __
606+
\___ \ / __| '__/ _ \/ _ \ '_ \
606607
___) | (__| | | __/ __/ | | |
607608
|____/ \___|_| \___|\___|_| |_|
608-
609+
609610
*/
610611

611612
/**
@@ -626,7 +627,7 @@ NAN_METHOD(getPixelColor)
626627
{
627628
return Nan::ThrowError("Invalid number of arguments.");
628629
}
629-
630+
630631
MMBitmapRef bitmap;
631632
MMRGBHex color;
632633

@@ -641,9 +642,9 @@ NAN_METHOD(getPixelColor)
641642
bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, 1, 1));
642643

643644
color = MMRGBHexAtPoint(bitmap, 0, 0);
644-
645+
645646
char hex[7];
646-
647+
647648
padHex(color, hex);
648649

649650
destroyMMBitmap(bitmap);
@@ -665,18 +666,18 @@ NAN_METHOD(getScreenSize)
665666
info.GetReturnValue().Set(obj);
666667
}
667668

668-
NAN_METHOD(captureScreen)
669+
NAN_METHOD(captureScreen)
669670
{
670671
size_t x;
671672
size_t y;
672673
size_t w;
673674
size_t h;
674-
675-
//If user has provided screen coords, use them!
675+
676+
//If user has provided screen coords, use them!
676677
if (info.Length() == 4)
677678
{
678679
//TODO: Make sure requested coords are within the screen bounds, or we get a seg fault.
679-
// An error message is much nicer!
680+
// An error message is much nicer!
680681

681682
x = info[0]->Int32Value();
682683
y = info[1]->Int32Value();
@@ -688,15 +689,15 @@ NAN_METHOD(captureScreen)
688689
//We're getting the full screen.
689690
x = 0;
690691
y = 0;
691-
692+
692693
//Get screen size.
693694
MMSize displaySize = getMainDisplaySize();
694695
w = displaySize.width;
695696
h = displaySize.height;
696697
}
697-
698+
698699
MMBitmapRef bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, w, h));
699-
700+
700701
uint32_t bufferSize = bitmap->bytewidth * bitmap->height;
701702
Local<Object> buffer = Nan::NewBuffer((char*)bitmap->imageBuffer, bufferSize, destroyMMBitmapBuffer, NULL).ToLocalChecked();
702703

@@ -707,17 +708,17 @@ NAN_METHOD(captureScreen)
707708
Nan::Set(obj, Nan::New("bitsPerPixel").ToLocalChecked(), Nan::New<Number>(bitmap->bitsPerPixel));
708709
Nan::Set(obj, Nan::New("bytesPerPixel").ToLocalChecked(), Nan::New<Number>(bitmap->bytesPerPixel));
709710
Nan::Set(obj, Nan::New("image").ToLocalChecked(), buffer);
710-
711+
711712
info.GetReturnValue().Set(obj);
712713
}
713714

714715
/*
715-
____ _ _
716-
| __ )(_) |_ _ __ ___ __ _ _ __
717-
| _ \| | __| '_ ` _ \ / _` | '_ \
716+
____ _ _
717+
| __ )(_) |_ _ __ ___ __ _ _ __
718+
| _ \| | __| '_ ` _ \ / _` | '_ \
718719
| |_) | | |_| | | | | | (_| | |_) |
719-
|____/|_|\__|_| |_| |_|\__,_| .__/
720-
|_|
720+
|____/|_|\__|_| |_| |_|\__,_| .__/
721+
|_|
721722
*/
722723

723724
class BMP
@@ -732,7 +733,7 @@ class BMP
732733
};
733734

734735
//Convert object from Javascript to a C++ class (BMP).
735-
BMP buildBMP(Local<Object> info)
736+
BMP buildBMP(Local<Object> info)
736737
{
737738
Local<Object> obj = Nan::To<v8::Object>(info).ToLocalChecked();
738739

@@ -804,7 +805,7 @@ NAN_MODULE_INIT(InitAll)
804805

805806
Nan::Set(target, Nan::New("mouseToggle").ToLocalChecked(),
806807
Nan::GetFunction(Nan::New<FunctionTemplate>(mouseToggle)).ToLocalChecked());
807-
808+
808809
Nan::Set(target, Nan::New("scrollMouse").ToLocalChecked(),
809810
Nan::GetFunction(Nan::New<FunctionTemplate>(scrollMouse)).ToLocalChecked());
810811

@@ -831,10 +832,10 @@ NAN_MODULE_INIT(InitAll)
831832

832833
Nan::Set(target, Nan::New("getScreenSize").ToLocalChecked(),
833834
Nan::GetFunction(Nan::New<FunctionTemplate>(getScreenSize)).ToLocalChecked());
834-
835+
835836
Nan::Set(target, Nan::New("captureScreen").ToLocalChecked(),
836837
Nan::GetFunction(Nan::New<FunctionTemplate>(captureScreen)).ToLocalChecked());
837-
838+
838839
Nan::Set(target, Nan::New("getColor").ToLocalChecked(),
839840
Nan::GetFunction(Nan::New<FunctionTemplate>(getColor)).ToLocalChecked());
840841
}

0 commit comments

Comments
 (0)