@@ -483,7 +483,6 @@ Napi::Number _keyTap(const Napi::CallbackInfo &info)
483
483
break ;
484
484
default :
485
485
tapKeyCode (key, flags);
486
- microsleep (keyboardDelay);
487
486
}
488
487
489
488
return Napi::Number::New (env, 1 );
@@ -496,7 +495,7 @@ Napi::Number _keyToggle(const Napi::CallbackInfo &info)
496
495
MMKeyFlags flags = MOD_NONE;
497
496
MMKeyCode key;
498
497
499
- bool down;
498
+ bool down = false ;
500
499
501
500
// Get arguments from JavaScript.
502
501
std::string keyName = info[0 ].As <Napi::String>();
@@ -552,7 +551,6 @@ Napi::Number _keyToggle(const Napi::CallbackInfo &info)
552
551
break ;
553
552
default :
554
553
toggleKeyCode (key, down, flags);
555
- microsleep (keyboardDelay);
556
554
}
557
555
558
556
return Napi::Number::New (env, 1 );
@@ -576,7 +574,7 @@ Napi::Number _typeStringDelayed(const Napi::CallbackInfo &info)
576
574
std::string stringToType = info[0 ].As <Napi::String>();
577
575
size_t cpm = info[1 ].As <Napi::Number>().Int32Value ();
578
576
579
- typeStringDelayed (stringToType.c_str (), cpm);
577
+ typeStringDelayed (stringToType.c_str (), ( unsigned int ) cpm);
580
578
581
579
return Napi::Number::New (env, 1 );
582
580
}
@@ -613,8 +611,8 @@ Napi::Object _getScreenSize(const Napi::CallbackInfo &info)
613
611
614
612
// Create our return object.
615
613
Napi::Object obj = Napi::Object::New (env);
616
- obj.Set (Napi::String::New (env, " width" ), Napi::Number::New (env, displaySize.width ));
617
- obj.Set (Napi::String::New (env, " height" ), Napi::Number::New (env, displaySize.height ));
614
+ obj.Set (Napi::String::New (env, " width" ), Napi::Number::New (env, ( double ) displaySize.width ));
615
+ obj.Set (Napi::String::New (env, " height" ), Napi::Number::New (env, ( double ) displaySize.height ));
618
616
619
617
return obj;
620
618
}
@@ -660,7 +658,7 @@ Napi::Number _highlight(const Napi::CallbackInfo &info)
660
658
y = info[1 ].As <Napi::Number>().Int32Value ();
661
659
width = info[2 ].As <Napi::Number>().Int32Value ();
662
660
height = info[3 ].As <Napi::Number>().Int32Value ();
663
- duration = info[4 ].As <Napi::Number>().Int64Value ();
661
+ duration = ( int ) info[4 ].As <Napi::Number>().Int64Value ();
664
662
opacity = info[5 ].As <Napi::Number>().FloatValue ();
665
663
666
664
highlight (x, y, width, height, duration, opacity);
@@ -673,7 +671,7 @@ Napi::Number _getActiveWindow(const Napi::CallbackInfo &info) {
673
671
Napi::Env env = info.Env ();
674
672
675
673
WindowHandle windowHandle = getActiveWindow ();
676
- return Napi::Number::New (env, windowHandle);
674
+ return Napi::Number::New (env, ( double ) windowHandle);
677
675
}
678
676
679
677
Napi::Array _getWindows (const Napi::CallbackInfo &info) {
@@ -683,7 +681,7 @@ Napi::Array _getWindows(const Napi::CallbackInfo &info) {
683
681
auto arr = Napi::Array::New (env, windowHandles.size ());
684
682
685
683
for (size_t idx = 0 ; idx < windowHandles.size (); ++idx) {
686
- arr[idx] = windowHandles[idx];
684
+ arr[( uint32_t ) idx] = windowHandles[idx];
687
685
}
688
686
689
687
return arr;
@@ -696,10 +694,10 @@ Napi::Object _getWindowRect(const Napi::CallbackInfo &info) {
696
694
MMRect windowRect = getWindowRect (windowHandle);
697
695
698
696
Napi::Object obj = Napi::Object::New (env);
699
- obj.Set (Napi::String::New (env, " x" ), Napi::Number::New (env, windowRect.origin .x ));
700
- obj.Set (Napi::String::New (env, " y" ), Napi::Number::New (env, windowRect.origin .y ));
701
- obj.Set (Napi::String::New (env, " width" ), Napi::Number::New (env, windowRect.size .width ));
702
- obj.Set (Napi::String::New (env, " height" ), Napi::Number::New (env, windowRect.size .height ));
697
+ obj.Set (Napi::String::New (env, " x" ), Napi::Number::New (env, ( double ) windowRect.origin .x ));
698
+ obj.Set (Napi::String::New (env, " y" ), Napi::Number::New (env, ( double ) windowRect.origin .y ));
699
+ obj.Set (Napi::String::New (env, " width" ), Napi::Number::New (env, ( double ) windowRect.size .width ));
700
+ obj.Set (Napi::String::New (env, " height" ), Napi::Number::New (env, ( double ) windowRect.size .height ));
703
701
704
702
return obj;
705
703
}
@@ -758,14 +756,18 @@ Napi::Object _captureScreen(const Napi::CallbackInfo &info)
758
756
}
759
757
760
758
MMBitmapRef bitmap = copyMMBitmapFromDisplayInRect (MMRectMake (x, y, w, h));
759
+
760
+ if (bitmap == NULL ) {
761
+ throw Napi::Error::New (env, " Error: Failed to capture screen" );
762
+ }
761
763
762
- uint32_t bufferSize = bitmap->bytewidth * bitmap->height ;
764
+ uint32_t bufferSize = ( uint32_t )( bitmap->bytewidth * bitmap->height ) ;
763
765
Napi::Buffer<char > buffer = Napi::Buffer<char >::New (env, (char *)bitmap->imageBuffer , bufferSize, finalizer);
764
766
765
767
Napi::Object obj = Napi::Object::New (env);
766
- obj.Set (Napi::String::New (env, " width" ), Napi::Number::New (env, bitmap->width ));
767
- obj.Set (Napi::String::New (env, " height" ), Napi::Number::New (env, bitmap->height ));
768
- obj.Set (Napi::String::New (env, " byteWidth" ), Napi::Number::New (env, bitmap->bytewidth ));
768
+ obj.Set (Napi::String::New (env, " width" ), Napi::Number::New (env, ( double ) bitmap->width ));
769
+ obj.Set (Napi::String::New (env, " height" ), Napi::Number::New (env, ( double ) bitmap->height ));
770
+ obj.Set (Napi::String::New (env, " byteWidth" ), Napi::Number::New (env, ( double ) bitmap->bytewidth ));
769
771
obj.Set (Napi::String::New (env, " bitsPerPixel" ), Napi::Number::New (env, bitmap->bitsPerPixel ));
770
772
obj.Set (Napi::String::New (env, " bytesPerPixel" ), Napi::Number::New (env, bitmap->bytesPerPixel ));
771
773
obj.Set (Napi::String::New (env, " image" ), buffer);
0 commit comments